Merge pull request #215 from deepak1556/devtools_dock_state_patch

pass the current dock state to devtools url when available
This commit is contained in:
Cheng Zhao 2016-04-20 13:34:11 +09:00
commit 80fff89f88
3 changed files with 24 additions and 9 deletions

View file

@ -34,7 +34,7 @@ class InspectableWebContents {
virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0;
virtual InspectableWebContentsDelegate* GetDelegate() const = 0;
virtual void SetCanDock(bool can_dock) = 0;
virtual void SetDockState(const std::string& state) = 0;
virtual void ShowDevTools() = 0;
virtual void CloseDevTools() = 0;
virtual bool IsDevToolsViewShowing() = 0;

View file

@ -116,6 +116,18 @@ GURL GetRemoteBaseURL() {
content::GetWebKitRevision().c_str()));
}
GURL GetDevToolsURL(
bool can_dock,
const std::string& dock_state) {
auto url_string =
base::StringPrintf(kChromeUIDevToolsURL,
GetRemoteBaseURL().spec().c_str(),
can_dock ? "true" : "");
if (!dock_state.empty())
url_string += "&settings={\"currentDockState\":\"\\\"" + dock_state + "\\\"\"}&";
return GURL(url_string);
}
// ResponseWriter -------------------------------------------------------------
class ResponseWriter : public net::URLFetcherResponseWriter {
@ -234,8 +246,13 @@ InspectableWebContentsDelegate* InspectableWebContentsImpl::GetDelegate() const
return delegate_;
}
void InspectableWebContentsImpl::SetCanDock(bool can_dock) {
can_dock_ = can_dock;
void InspectableWebContentsImpl::SetDockState(const std::string& state) {
if (state == "detach") {
can_dock_ = false;
} else {
can_dock_ = true;
dock_state_ = state;
}
}
void InspectableWebContentsImpl::ShowDevTools() {
@ -254,11 +271,8 @@ void InspectableWebContentsImpl::ShowDevTools() {
agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get());
agent_host_->AttachClient(this);
GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL,
GetRemoteBaseURL().spec().c_str(),
can_dock_ ? "true" : ""));
devtools_web_contents_->GetController().LoadURL(
devtools_url,
GetDevToolsURL(can_dock_, dock_state_),
content::Referrer(),
ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());

View file

@ -50,7 +50,7 @@ class InspectableWebContentsImpl :
void SetDelegate(InspectableWebContentsDelegate* delegate) override;
InspectableWebContentsDelegate* GetDelegate() const override;
void SetCanDock(bool can_dock) override;
void SetDockState(const std::string& state) override;
void ShowDevTools() override;
void CloseDevTools() override;
bool IsDevToolsViewShowing() override;
@ -168,12 +168,13 @@ class InspectableWebContentsImpl :
DevToolsContentsResizingStrategy contents_resizing_strategy_;
gfx::Rect devtools_bounds_;
bool can_dock_;
std::string dock_state_;
using PendingRequestsMap = std::map<const net::URLFetcher*, DispatchCallback>;
PendingRequestsMap pending_requests_;
InspectableWebContentsDelegate* delegate_; // weak references.
PrefService* pref_service_; // weak reference.
PrefService* pref_service_; // weak reference.
scoped_ptr<content::WebContents> web_contents_;
scoped_ptr<content::WebContents> devtools_web_contents_;