Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jun 5, 2015
1 parent 019e663 commit c4cf700
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
21 changes: 14 additions & 7 deletions browser/inspectable_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "content/public/browser/web_contents.h"

namespace base {
class Value;
}

namespace content {
class DevToolsAgentHost;
}
Expand All @@ -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.
Expand All @@ -26,16 +29,20 @@ class InspectableWebContents {
virtual InspectableWebContentsView* GetView() const = 0;
virtual content::WebContents* GetWebContents() const = 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;
// 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 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
Expand Down
20 changes: 15 additions & 5 deletions browser/inspectable_web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) ||
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
22 changes: 8 additions & 14 deletions browser/inspectable_web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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_;
Expand Down

0 comments on commit c4cf700

Please sign in to comment.