зеркало из https://github.com/electron/electron.git
Clean up code
This commit is contained in:
Родитель
aa926680a2
Коммит
05f182f650
|
@ -3,6 +3,10 @@
|
|||
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
namespace base {
|
||||
class Value;
|
||||
}
|
||||
|
||||
namespace content {
|
||||
class DevToolsAgentHost;
|
||||
}
|
||||
|
@ -14,8 +18,7 @@ class InspectableWebContentsView;
|
|||
|
||||
class InspectableWebContents {
|
||||
public:
|
||||
static InspectableWebContents* Create(
|
||||
const content::WebContents::CreateParams&);
|
||||
static InspectableWebContents* Create(const content::WebContents::CreateParams&);
|
||||
|
||||
// The returned InspectableWebContents takes ownership of the passed-in
|
||||
// WebContents.
|
||||
|
@ -26,16 +29,20 @@ class InspectableWebContents {
|
|||
virtual InspectableWebContentsView* GetView() const = 0;
|
||||
virtual content::WebContents* GetWebContents() const = 0;
|
||||
|
||||
virtual void SetCanDock(bool can_dock) = 0;
|
||||
virtual void ShowDevTools() = 0;
|
||||
// Close the DevTools completely instead of just hide it.
|
||||
virtual void CloseDevTools() = 0;
|
||||
virtual bool IsDevToolsViewShowing() = 0;
|
||||
virtual void AttachTo(const scoped_refptr<content::DevToolsAgentHost>&) = 0;
|
||||
|
||||
// The delegate manages its own life.
|
||||
virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0;
|
||||
virtual InspectableWebContentsDelegate* GetDelegate() const = 0;
|
||||
|
||||
virtual void SetCanDock(bool can_dock) = 0;
|
||||
virtual void ShowDevTools() = 0;
|
||||
virtual void CloseDevTools() = 0;
|
||||
virtual bool IsDevToolsViewShowing() = 0;
|
||||
virtual void AttachTo(const scoped_refptr<content::DevToolsAgentHost>&) = 0;
|
||||
virtual void Detach() = 0;
|
||||
virtual void CallClientFunction(const std::string& function_name,
|
||||
const base::Value* arg1,
|
||||
const base::Value* arg2,
|
||||
const base::Value* arg3) = 0;
|
||||
};
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -160,8 +160,8 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) {
|
|||
InspectableWebContentsImpl::InspectableWebContentsImpl(
|
||||
content::WebContents* web_contents)
|
||||
: web_contents_(web_contents),
|
||||
can_dock_(true),
|
||||
frontend_loaded_(false),
|
||||
can_dock_(true),
|
||||
delegate_(nullptr),
|
||||
weak_factory_(this) {
|
||||
auto context = static_cast<BrowserContext*>(web_contents_->GetBrowserContext());
|
||||
|
@ -183,6 +183,14 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const {
|
|||
return web_contents_.get();
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::SetDelegate(InspectableWebContentsDelegate* delegate) {
|
||||
delegate_ = delegate;
|
||||
}
|
||||
|
||||
InspectableWebContentsDelegate* InspectableWebContentsImpl::GetDelegate() const {
|
||||
return delegate_;
|
||||
}
|
||||
|
||||
void InspectableWebContentsImpl::SetCanDock(bool can_dock) {
|
||||
can_dock_ = can_dock;
|
||||
}
|
||||
|
@ -429,7 +437,7 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::st
|
|||
base::ListValue empty_params;
|
||||
base::ListValue* params = &empty_params;
|
||||
|
||||
base::DictionaryValue* dict = NULL;
|
||||
base::DictionaryValue* dict = nullptr;
|
||||
scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
|
||||
if (!parsed_message ||
|
||||
!parsed_message->GetAsDictionary(&dict) ||
|
||||
|
@ -471,7 +479,7 @@ void InspectableWebContentsImpl::DispatchProtocolMessage(
|
|||
for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
|
||||
base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize));
|
||||
CallClientFunction("DevToolsAPI.dispatchMessageChunk",
|
||||
&message_value, pos ? NULL : &total_size, NULL);
|
||||
&message_value, pos ? nullptr : &total_size, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -488,9 +496,11 @@ void InspectableWebContentsImpl::AboutToNavigateRenderFrame(
|
|||
}
|
||||
|
||||
void InspectableWebContentsImpl::WebContentsDestroyed() {
|
||||
frontend_loaded_ = false;
|
||||
Observe(nullptr);
|
||||
Detach();
|
||||
frontend_loaded_ = false;
|
||||
agent_host_ = nullptr;
|
||||
embedder_message_dispatcher_ = nullptr;
|
||||
|
||||
for (const auto& pair : pending_requests_)
|
||||
delete pair.first;
|
||||
|
@ -548,7 +558,7 @@ void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* sourc
|
|||
response.SetInteger("statusCode", rh ? rh->response_code() : 200);
|
||||
response.Set("headers", headers);
|
||||
|
||||
void* iterator = NULL;
|
||||
void* iterator = nullptr;
|
||||
std::string name;
|
||||
std::string value;
|
||||
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
|
||||
|
|
|
@ -47,29 +47,23 @@ class InspectableWebContentsImpl :
|
|||
InspectableWebContentsView* GetView() const override;
|
||||
content::WebContents* GetWebContents() const override;
|
||||
|
||||
void SetDelegate(InspectableWebContentsDelegate* delegate) override;
|
||||
InspectableWebContentsDelegate* GetDelegate() const override;
|
||||
void SetCanDock(bool can_dock) override;
|
||||
void ShowDevTools() override;
|
||||
void CloseDevTools() override;
|
||||
bool IsDevToolsViewShowing() override;
|
||||
void AttachTo(const scoped_refptr<content::DevToolsAgentHost>&) override;
|
||||
|
||||
void Detach();
|
||||
void Detach() override;
|
||||
void CallClientFunction(const std::string& function_name,
|
||||
const base::Value* arg1,
|
||||
const base::Value* arg2,
|
||||
const base::Value* arg3);
|
||||
const base::Value* arg3) override;
|
||||
|
||||
// Return the last position and size of devtools window.
|
||||
gfx::Rect GetDevToolsBounds() const;
|
||||
void SaveDevToolsBounds(const gfx::Rect& bounds);
|
||||
|
||||
virtual void SetDelegate(InspectableWebContentsDelegate* delegate) {
|
||||
delegate_ = delegate;
|
||||
}
|
||||
virtual InspectableWebContentsDelegate* GetDelegate() const {
|
||||
return delegate_;
|
||||
}
|
||||
|
||||
content::WebContents* devtools_web_contents() {
|
||||
return devtools_web_contents_.get();
|
||||
}
|
||||
|
@ -159,17 +153,17 @@ class InspectableWebContentsImpl :
|
|||
scoped_ptr<content::WebContents> web_contents_;
|
||||
scoped_ptr<content::WebContents> devtools_web_contents_;
|
||||
scoped_ptr<InspectableWebContentsView> view_;
|
||||
|
||||
bool frontend_loaded_;
|
||||
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
||||
scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
|
||||
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
|
||||
|
||||
DevToolsContentsResizingStrategy contents_resizing_strategy_;
|
||||
gfx::Rect devtools_bounds_;
|
||||
bool can_dock_;
|
||||
bool frontend_loaded_;
|
||||
|
||||
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
|
||||
|
||||
InspectableWebContentsDelegate* delegate_;
|
||||
InspectableWebContentsDelegate* delegate_; // weak references.
|
||||
|
||||
using PendingRequestsMap = std::map<const net::URLFetcher*, DispatchCallback>;
|
||||
PendingRequestsMap pending_requests_;
|
||||
|
|
Загрузка…
Ссылка в новой задаче