Clean up code
This commit is contained in:
parent
aa926680a2
commit
05f182f650
3 changed files with 39 additions and 28 deletions
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
class Value;
|
||||||
|
}
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class DevToolsAgentHost;
|
class DevToolsAgentHost;
|
||||||
}
|
}
|
||||||
|
@ -14,8 +18,7 @@ class InspectableWebContentsView;
|
||||||
|
|
||||||
class InspectableWebContents {
|
class InspectableWebContents {
|
||||||
public:
|
public:
|
||||||
static InspectableWebContents* Create(
|
static InspectableWebContents* Create(const content::WebContents::CreateParams&);
|
||||||
const content::WebContents::CreateParams&);
|
|
||||||
|
|
||||||
// The returned InspectableWebContents takes ownership of the passed-in
|
// The returned InspectableWebContents takes ownership of the passed-in
|
||||||
// WebContents.
|
// WebContents.
|
||||||
|
@ -26,16 +29,20 @@ class InspectableWebContents {
|
||||||
virtual InspectableWebContentsView* GetView() const = 0;
|
virtual InspectableWebContentsView* GetView() const = 0;
|
||||||
virtual content::WebContents* GetWebContents() 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.
|
// The delegate manages its own life.
|
||||||
virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0;
|
virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0;
|
||||||
virtual InspectableWebContentsDelegate* GetDelegate() const = 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
|
} // namespace brightray
|
||||||
|
|
|
@ -160,8 +160,8 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) {
|
||||||
InspectableWebContentsImpl::InspectableWebContentsImpl(
|
InspectableWebContentsImpl::InspectableWebContentsImpl(
|
||||||
content::WebContents* web_contents)
|
content::WebContents* web_contents)
|
||||||
: web_contents_(web_contents),
|
: web_contents_(web_contents),
|
||||||
can_dock_(true),
|
|
||||||
frontend_loaded_(false),
|
frontend_loaded_(false),
|
||||||
|
can_dock_(true),
|
||||||
delegate_(nullptr),
|
delegate_(nullptr),
|
||||||
weak_factory_(this) {
|
weak_factory_(this) {
|
||||||
auto context = static_cast<BrowserContext*>(web_contents_->GetBrowserContext());
|
auto context = static_cast<BrowserContext*>(web_contents_->GetBrowserContext());
|
||||||
|
@ -183,6 +183,14 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const {
|
||||||
return web_contents_.get();
|
return web_contents_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InspectableWebContentsImpl::SetDelegate(InspectableWebContentsDelegate* delegate) {
|
||||||
|
delegate_ = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
InspectableWebContentsDelegate* InspectableWebContentsImpl::GetDelegate() const {
|
||||||
|
return delegate_;
|
||||||
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::SetCanDock(bool can_dock) {
|
void InspectableWebContentsImpl::SetCanDock(bool can_dock) {
|
||||||
can_dock_ = can_dock;
|
can_dock_ = can_dock;
|
||||||
}
|
}
|
||||||
|
@ -429,7 +437,7 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::st
|
||||||
base::ListValue empty_params;
|
base::ListValue empty_params;
|
||||||
base::ListValue* params = &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));
|
scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
|
||||||
if (!parsed_message ||
|
if (!parsed_message ||
|
||||||
!parsed_message->GetAsDictionary(&dict) ||
|
!parsed_message->GetAsDictionary(&dict) ||
|
||||||
|
@ -471,7 +479,7 @@ void InspectableWebContentsImpl::DispatchProtocolMessage(
|
||||||
for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
|
for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
|
||||||
base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize));
|
base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize));
|
||||||
CallClientFunction("DevToolsAPI.dispatchMessageChunk",
|
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() {
|
void InspectableWebContentsImpl::WebContentsDestroyed() {
|
||||||
|
frontend_loaded_ = false;
|
||||||
Observe(nullptr);
|
Observe(nullptr);
|
||||||
Detach();
|
Detach();
|
||||||
frontend_loaded_ = false;
|
agent_host_ = nullptr;
|
||||||
|
embedder_message_dispatcher_ = nullptr;
|
||||||
|
|
||||||
for (const auto& pair : pending_requests_)
|
for (const auto& pair : pending_requests_)
|
||||||
delete pair.first;
|
delete pair.first;
|
||||||
|
@ -548,7 +558,7 @@ void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* sourc
|
||||||
response.SetInteger("statusCode", rh ? rh->response_code() : 200);
|
response.SetInteger("statusCode", rh ? rh->response_code() : 200);
|
||||||
response.Set("headers", headers);
|
response.Set("headers", headers);
|
||||||
|
|
||||||
void* iterator = NULL;
|
void* iterator = nullptr;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string value;
|
std::string value;
|
||||||
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
|
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value))
|
||||||
|
|
|
@ -47,29 +47,23 @@ class InspectableWebContentsImpl :
|
||||||
InspectableWebContentsView* GetView() const override;
|
InspectableWebContentsView* GetView() const override;
|
||||||
content::WebContents* GetWebContents() const override;
|
content::WebContents* GetWebContents() const override;
|
||||||
|
|
||||||
|
void SetDelegate(InspectableWebContentsDelegate* delegate) override;
|
||||||
|
InspectableWebContentsDelegate* GetDelegate() const override;
|
||||||
void SetCanDock(bool can_dock) override;
|
void SetCanDock(bool can_dock) override;
|
||||||
void ShowDevTools() override;
|
void ShowDevTools() override;
|
||||||
void CloseDevTools() override;
|
void CloseDevTools() override;
|
||||||
bool IsDevToolsViewShowing() override;
|
bool IsDevToolsViewShowing() override;
|
||||||
void AttachTo(const scoped_refptr<content::DevToolsAgentHost>&) override;
|
void AttachTo(const scoped_refptr<content::DevToolsAgentHost>&) override;
|
||||||
|
void Detach() override;
|
||||||
void Detach();
|
|
||||||
void CallClientFunction(const std::string& function_name,
|
void CallClientFunction(const std::string& function_name,
|
||||||
const base::Value* arg1,
|
const base::Value* arg1,
|
||||||
const base::Value* arg2,
|
const base::Value* arg2,
|
||||||
const base::Value* arg3);
|
const base::Value* arg3) override;
|
||||||
|
|
||||||
// Return the last position and size of devtools window.
|
// Return the last position and size of devtools window.
|
||||||
gfx::Rect GetDevToolsBounds() const;
|
gfx::Rect GetDevToolsBounds() const;
|
||||||
void SaveDevToolsBounds(const gfx::Rect& bounds);
|
void SaveDevToolsBounds(const gfx::Rect& bounds);
|
||||||
|
|
||||||
virtual void SetDelegate(InspectableWebContentsDelegate* delegate) {
|
|
||||||
delegate_ = delegate;
|
|
||||||
}
|
|
||||||
virtual InspectableWebContentsDelegate* GetDelegate() const {
|
|
||||||
return delegate_;
|
|
||||||
}
|
|
||||||
|
|
||||||
content::WebContents* devtools_web_contents() {
|
content::WebContents* devtools_web_contents() {
|
||||||
return devtools_web_contents_.get();
|
return devtools_web_contents_.get();
|
||||||
}
|
}
|
||||||
|
@ -159,17 +153,17 @@ class InspectableWebContentsImpl :
|
||||||
scoped_ptr<content::WebContents> web_contents_;
|
scoped_ptr<content::WebContents> web_contents_;
|
||||||
scoped_ptr<content::WebContents> devtools_web_contents_;
|
scoped_ptr<content::WebContents> devtools_web_contents_;
|
||||||
scoped_ptr<InspectableWebContentsView> view_;
|
scoped_ptr<InspectableWebContentsView> view_;
|
||||||
|
|
||||||
|
bool frontend_loaded_;
|
||||||
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
||||||
scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
|
scoped_ptr<content::DevToolsFrontendHost> frontend_host_;
|
||||||
|
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
|
||||||
|
|
||||||
DevToolsContentsResizingStrategy contents_resizing_strategy_;
|
DevToolsContentsResizingStrategy contents_resizing_strategy_;
|
||||||
gfx::Rect devtools_bounds_;
|
gfx::Rect devtools_bounds_;
|
||||||
bool can_dock_;
|
bool can_dock_;
|
||||||
bool frontend_loaded_;
|
|
||||||
|
|
||||||
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
|
InspectableWebContentsDelegate* delegate_; // weak references.
|
||||||
|
|
||||||
InspectableWebContentsDelegate* delegate_;
|
|
||||||
|
|
||||||
using PendingRequestsMap = std::map<const net::URLFetcher*, DispatchCallback>;
|
using PendingRequestsMap = std::map<const net::URLFetcher*, DispatchCallback>;
|
||||||
PendingRequestsMap pending_requests_;
|
PendingRequestsMap pending_requests_;
|
||||||
|
|
Loading…
Reference in a new issue