| Index: chrome/browser/devtools/devtools_window.cc
|
| ===================================================================
|
| --- chrome/browser/devtools/devtools_window.cc (revision 212931)
|
| +++ chrome/browser/devtools/devtools_window.cc (working copy)
|
| @@ -103,74 +103,141 @@
|
| const int kMinContentsSize = 50;
|
| const int kMinimizedDevToolsHeight = 24;
|
|
|
| +
|
| +// DevToolsConfirmInfoBarDelegate ---------------------------------------------
|
| +
|
| +typedef Callback<void(bool)> ConfirmInfoBarCallback;
|
| +
|
| +class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| + public:
|
| + DevToolsConfirmInfoBarDelegate(InfoBarService* infobar_service,
|
| + const ConfirmInfoBarCallback& callback,
|
| + string16 message);
|
| +
|
| + virtual string16 GetMessageText() const OVERRIDE;
|
| + virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
|
| + virtual bool Accept() OVERRIDE;
|
| + virtual bool Cancel() OVERRIDE;
|
| +
|
| + private:
|
| + virtual ~DevToolsConfirmInfoBarDelegate();
|
| +
|
| + ConfirmInfoBarCallback callback_;
|
| + string16 message_;
|
| +};
|
| +
|
| +DevToolsConfirmInfoBarDelegate::DevToolsConfirmInfoBarDelegate(
|
| + InfoBarService* infobar_service,
|
| + const ConfirmInfoBarCallback& callback,
|
| + string16 message)
|
| + : ConfirmInfoBarDelegate(infobar_service),
|
| + callback_(callback),
|
| + message_(message) {
|
| +}
|
| +
|
| +string16 DevToolsConfirmInfoBarDelegate::GetMessageText() const {
|
| + return message_;
|
| +}
|
| +
|
| +string16 DevToolsConfirmInfoBarDelegate::GetButtonLabel(
|
| + InfoBarButton button) const {
|
| + return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
|
| + IDS_DEV_TOOLS_CONFIRM_ALLOW_BUTTON : IDS_DEV_TOOLS_CONFIRM_DENY_BUTTON);
|
| +}
|
| +
|
| +bool DevToolsConfirmInfoBarDelegate::Accept() {
|
| + callback_.Run(true);
|
| + callback_.Reset();
|
| + return true;
|
| +}
|
| +
|
| +bool DevToolsConfirmInfoBarDelegate::Cancel() {
|
| + callback_.Run(false);
|
| + callback_.Reset();
|
| + return true;
|
| +}
|
| +
|
| +DevToolsConfirmInfoBarDelegate::~DevToolsConfirmInfoBarDelegate() {
|
| + if (!callback_.is_null()) {
|
| + callback_.Run(false);
|
| + }
|
| +}
|
| +
|
| +
|
| +// DevToolsWindow::InspectedWebContentsObserver -------------------------------
|
| +
|
| class DevToolsWindow::InspectedWebContentsObserver
|
| : public content::WebContentsObserver {
|
| public:
|
| - explicit InspectedWebContentsObserver(content::WebContents* web_contents)
|
| - : WebContentsObserver(web_contents) {
|
| + explicit InspectedWebContentsObserver(content::WebContents* web_contents);
|
| +
|
| + content::WebContents* web_contents() {
|
| + return WebContentsObserver::web_contents();
|
| }
|
| -
|
| - content::WebContents* Get() { return web_contents(); }
|
| };
|
|
|
| +DevToolsWindow::InspectedWebContentsObserver::InspectedWebContentsObserver(
|
| + content::WebContents* web_contents)
|
| + : WebContentsObserver(web_contents) {
|
| +}
|
| +
|
| +
|
| +// DevToolsWindow::FrontendWebContentsObserver --------------------------------
|
| +
|
| class DevToolsWindow::FrontendWebContentsObserver
|
| : public content::WebContentsObserver {
|
| public:
|
| - explicit FrontendWebContentsObserver(content::WebContents* web_contents)
|
| - : WebContentsObserver(web_contents) {
|
| - }
|
| + explicit FrontendWebContentsObserver(content::WebContents* web_contents);
|
| +
|
| private:
|
| // Overriden from contents::WebContentsObserver.
|
| virtual void AboutToNavigateRenderView(
|
| - RenderViewHost* render_view_host) OVERRIDE {
|
| - content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host);
|
| - }
|
| + RenderViewHost* render_view_host) OVERRIDE;
|
| };
|
|
|
| -typedef Callback<void(bool)> ConfirmInfoBarCallback;
|
| +DevToolsWindow::FrontendWebContentsObserver::FrontendWebContentsObserver(
|
| + content::WebContents* web_contents)
|
| + : WebContentsObserver(web_contents) {
|
| +}
|
|
|
| -class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| - public:
|
| - DevToolsConfirmInfoBarDelegate(
|
| - InfoBarService* infobar_service,
|
| - const ConfirmInfoBarCallback& callback,
|
| - string16 message)
|
| - : ConfirmInfoBarDelegate(infobar_service),
|
| - callback_(callback),
|
| - message_(message) {
|
| - }
|
| +void DevToolsWindow::FrontendWebContentsObserver::AboutToNavigateRenderView(
|
| + content::RenderViewHost* render_view_host) {
|
| + content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host);
|
| +}
|
|
|
| - virtual string16 GetMessageText() const OVERRIDE { return message_; }
|
|
|
| - virtual bool Accept() OVERRIDE {
|
| - callback_.Run(true);
|
| - callback_.Reset();
|
| - return true;
|
| - }
|
| +// DevToolsWindow -------------------------------------------------------------
|
|
|
| - virtual bool Cancel() OVERRIDE {
|
| - callback_.Run(false);
|
| - callback_.Reset();
|
| - return true;
|
| - }
|
| +namespace {
|
|
|
| - virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE {
|
| - return l10n_util::GetStringUTF16((button == BUTTON_OK)
|
| - ? IDS_DEV_TOOLS_CONFIRM_ALLOW_BUTTON
|
| - : IDS_DEV_TOOLS_CONFIRM_DENY_BUTTON);
|
| - }
|
| +std::string SkColorToRGBAString(SkColor color) {
|
| + // We convert the alpha using DoubleToString because StringPrintf will use
|
| + // locale specific formatters (e.g., use , instead of . in German).
|
| + return base::StringPrintf("rgba(%d,%d,%d,%s)", SkColorGetR(color),
|
| + SkColorGetG(color), SkColorGetB(color),
|
| + base::DoubleToString(SkColorGetA(color) / 255.0).c_str());
|
| +}
|
|
|
| - private:
|
| - virtual ~DevToolsConfirmInfoBarDelegate() {
|
| - if (!callback_.is_null()) {
|
| - callback_.Run(false);
|
| - }
|
| - }
|
| +DictionaryValue* CreateFileSystemValue(
|
| + DevToolsFileHelper::FileSystem file_system) {
|
| + DictionaryValue* file_system_value = new DictionaryValue();
|
| + file_system_value->SetString("fileSystemName", file_system.file_system_name);
|
| + file_system_value->SetString("rootURL", file_system.root_url);
|
| + file_system_value->SetString("fileSystemPath", file_system.file_system_path);
|
| + return file_system_value;
|
| +}
|
|
|
| - ConfirmInfoBarCallback callback_;
|
| - string16 message_;
|
| -};
|
| +} // namespace
|
|
|
| +DevToolsWindow::~DevToolsWindow() {
|
| + DevToolsWindowList& instances = g_instances.Get();
|
| + DevToolsWindowList::iterator it = std::find(instances.begin(),
|
| + instances.end(),
|
| + this);
|
| + DCHECK(it != instances.end());
|
| + instances.erase(it);
|
| +}
|
| +
|
| // static
|
| std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() {
|
| std::string wp_key;
|
| @@ -272,18 +339,6 @@
|
| }
|
|
|
| // static
|
| -void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh,
|
| - int x,
|
| - int y) {
|
| - scoped_refptr<DevToolsAgentHost> agent(
|
| - DevToolsAgentHost::GetOrCreateFor(inspected_rvh));
|
| - agent->InspectElement(x, y);
|
| - // TODO(loislo): we should initiate DevTools window opening from within
|
| - // renderer. Otherwise, we still can hit a race condition here.
|
| - OpenDevToolsWindow(inspected_rvh);
|
| -}
|
| -
|
| -// static
|
| void DevToolsWindow::OpenExternalFrontend(
|
| Profile* profile,
|
| const std::string& frontend_url,
|
| @@ -299,148 +354,75 @@
|
| }
|
|
|
| // static
|
| -DevToolsWindow* DevToolsWindow::Create(
|
| - Profile* profile,
|
| - const GURL& frontend_url,
|
| +DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
|
| RenderViewHost* inspected_rvh,
|
| - DevToolsDockSide dock_side,
|
| - bool shared_worker_frontend) {
|
| - // Create WebContents with devtools.
|
| - GURL url = GetDevToolsURL(profile, frontend_url, dock_side,
|
| - shared_worker_frontend);
|
| - return new DevToolsWindow(profile, url, inspected_rvh, dock_side);
|
| -}
|
| + bool force_open,
|
| + DevToolsToggleAction action) {
|
| + scoped_refptr<DevToolsAgentHost> agent(
|
| + DevToolsAgentHost::GetOrCreateFor(inspected_rvh));
|
| + DevToolsManager* manager = DevToolsManager::GetInstance();
|
| + DevToolsWindow* window = FindDevToolsWindow(agent.get());
|
| + bool do_open = force_open;
|
| + if (!window) {
|
| + Profile* profile = Profile::FromBrowserContext(
|
| + inspected_rvh->GetProcess()->GetBrowserContext());
|
| + DevToolsDockSide dock_side = GetDockSideFromPrefs(profile);
|
| + window = Create(profile, GURL(), inspected_rvh, dock_side, false);
|
| + manager->RegisterDevToolsClientHostFor(agent.get(),
|
| + window->frontend_host_.get());
|
| + do_open = true;
|
| + }
|
|
|
| -DevToolsWindow::DevToolsWindow(Profile* profile,
|
| - const GURL& url,
|
| - RenderViewHost* inspected_rvh,
|
| - DevToolsDockSide dock_side)
|
| - : profile_(profile),
|
| - browser_(NULL),
|
| - dock_side_(dock_side),
|
| - is_loaded_(false),
|
| - action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW),
|
| - weak_factory_(this),
|
| - width_(-1),
|
| - height_(-1),
|
| - dock_side_before_minimized_(dock_side) {
|
| - web_contents_ = WebContents::Create(WebContents::CreateParams(profile));
|
| - frontend_contents_observer_.reset(
|
| - new FrontendWebContentsObserver(web_contents_));
|
| + // Update toolbar to reflect DevTools changes.
|
| + window->UpdateBrowserToolbar();
|
|
|
| - web_contents_->GetController().LoadURL(url, content::Referrer(),
|
| - content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
|
| + // If window is docked and visible, we hide it on toggle. If window is
|
| + // undocked, we show (activate) it. If window is minimized, we maximize it.
|
| + if (window->dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED)
|
| + window->Restore();
|
| + else if (!window->IsDocked() || do_open)
|
| + window->Show(action);
|
| + else
|
| + window->CloseWindow();
|
|
|
| - frontend_host_.reset(
|
| - DevToolsClientHost::CreateDevToolsFrontendHost(web_contents_, this));
|
| - file_helper_.reset(new DevToolsFileHelper(web_contents_, profile));
|
| + return window;
|
| +}
|
|
|
| - g_instances.Get().push_back(this);
|
| - // Wipe out page icon so that the default application icon is used.
|
| - NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
|
| - entry->GetFavicon().image = gfx::Image();
|
| - entry->GetFavicon().valid = true;
|
| +// static
|
| +void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh,
|
| + int x,
|
| + int y) {
|
| + scoped_refptr<DevToolsAgentHost> agent(
|
| + DevToolsAgentHost::GetOrCreateFor(inspected_rvh));
|
| + agent->InspectElement(x, y);
|
| + // TODO(loislo): we should initiate DevTools window opening from within
|
| + // renderer. Otherwise, we still can hit a race condition here.
|
| + OpenDevToolsWindow(inspected_rvh);
|
| +}
|
|
|
| - // Register on-load actions.
|
| - registrar_.Add(
|
| - this,
|
| - content::NOTIFICATION_LOAD_STOP,
|
| - content::Source<NavigationController>(&web_contents_->GetController()));
|
| - registrar_.Add(
|
| - this,
|
| - chrome::NOTIFICATION_TAB_CLOSING,
|
| - content::Source<NavigationController>(&web_contents_->GetController()));
|
| - registrar_.Add(
|
| - this,
|
| - chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
|
| - content::Source<ThemeService>(
|
| - ThemeServiceFactory::GetForProfile(profile_)));
|
| - // There is no inspected_rvh in case of shared workers.
|
| - if (inspected_rvh)
|
| - inspected_contents_observer_.reset(new InspectedWebContentsObserver(
|
| - WebContents::FromRenderViewHost(inspected_rvh)));
|
| +// static
|
| +int DevToolsWindow::GetMinimumWidth() {
|
| + return kMinDevToolsWidth;
|
| }
|
|
|
| -DevToolsWindow::~DevToolsWindow() {
|
| - DevToolsWindowList& instances = g_instances.Get();
|
| - DevToolsWindowList::iterator it = std::find(instances.begin(),
|
| - instances.end(),
|
| - this);
|
| - DCHECK(it != instances.end());
|
| - instances.erase(it);
|
| +// static
|
| +int DevToolsWindow::GetMinimumHeight() {
|
| + return kMinDevToolsHeight;
|
| }
|
|
|
| -content::WebContents* DevToolsWindow::GetInspectedWebContents() {
|
| - if (!inspected_contents_observer_)
|
| - return NULL;
|
| - return inspected_contents_observer_->Get();
|
| +// static
|
| +int DevToolsWindow::GetMinimizedHeight() {
|
| + return kMinimizedDevToolsHeight;
|
| }
|
|
|
| void DevToolsWindow::InspectedContentsClosing() {
|
| Hide();
|
| }
|
|
|
| -void DevToolsWindow::Hide() {
|
| - if (IsDocked()) {
|
| - // Update dev tools to reflect removed dev tools window.
|
| - BrowserWindow* inspected_window = GetInspectedBrowserWindow();
|
| - if (inspected_window)
|
| - inspected_window->UpdateDevTools();
|
| - // In case of docked web_contents_, we own it so delete here.
|
| - delete web_contents_;
|
| -
|
| - delete this;
|
| - } else {
|
| - // First, initiate self-destruct to free all the registrars.
|
| - // Then close all tabs. Browser will take care of deleting web_contents_
|
| - // for us.
|
| - Browser* browser = browser_;
|
| - delete this;
|
| - browser->tab_strip_model()->CloseAllTabs();
|
| - }
|
| +RenderViewHost* DevToolsWindow::GetRenderViewHost() {
|
| + return web_contents_->GetRenderViewHost();
|
| }
|
|
|
| -void DevToolsWindow::Show(DevToolsToggleAction action) {
|
| - if (IsDocked()) {
|
| - Browser* inspected_browser;
|
| - int inspected_tab_index;
|
| - // Tell inspected browser to update splitter and switch to inspected panel.
|
| - if (!IsInspectedBrowserPopup() &&
|
| - FindInspectedBrowserAndTabIndex(&inspected_browser,
|
| - &inspected_tab_index)) {
|
| - BrowserWindow* inspected_window = inspected_browser->window();
|
| - web_contents_->SetDelegate(this);
|
| - inspected_window->UpdateDevTools();
|
| - web_contents_->GetView()->SetInitialFocus();
|
| - inspected_window->Show();
|
| - TabStripModel* tab_strip_model = inspected_browser->tab_strip_model();
|
| - tab_strip_model->ActivateTabAt(inspected_tab_index, true);
|
| - PrefsTabHelper::CreateForWebContents(web_contents_);
|
| - GetRenderViewHost()->SyncRendererPrefs();
|
| - ScheduleAction(action);
|
| - return;
|
| - } else {
|
| - // Sometimes we don't know where to dock. Stay undocked.
|
| - dock_side_ = DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| - }
|
| - }
|
| -
|
| - // Avoid consecutive window switching if the devtools window has been opened
|
| - // and the Inspect Element shortcut is pressed in the inspected tab.
|
| - bool should_show_window =
|
| - !browser_ || action != DEVTOOLS_TOGGLE_ACTION_INSPECT;
|
| -
|
| - if (!browser_)
|
| - CreateDevToolsBrowser();
|
| -
|
| - if (should_show_window) {
|
| - browser_->window()->Show();
|
| - web_contents_->GetView()->SetInitialFocus();
|
| - }
|
| -
|
| - ScheduleAction(action);
|
| -}
|
| -
|
| DevToolsClientHost* DevToolsWindow::GetDevToolsClientHostForTest() {
|
| return frontend_host_.get();
|
| }
|
| @@ -482,14 +464,6 @@
|
| return height_;
|
| }
|
|
|
| -int DevToolsWindow::GetMinimumWidth() {
|
| - return kMinDevToolsWidth;
|
| -}
|
| -
|
| -int DevToolsWindow::GetMinimumHeight() {
|
| - return kMinDevToolsHeight;
|
| -}
|
| -
|
| void DevToolsWindow::SetWidth(int width) {
|
| width_ = width;
|
| profile_->GetPrefs()->SetInteger(prefs::kDevToolsVSplitLocation, width);
|
| @@ -500,168 +474,216 @@
|
| profile_->GetPrefs()->SetInteger(prefs::kDevToolsHSplitLocation, height);
|
| }
|
|
|
| -int DevToolsWindow::GetMinimizedHeight() {
|
| - return kMinimizedDevToolsHeight;
|
| -}
|
| +void DevToolsWindow::Show(DevToolsToggleAction action) {
|
| + if (IsDocked()) {
|
| + Browser* inspected_browser;
|
| + int inspected_tab_index;
|
| + // Tell inspected browser to update splitter and switch to inspected panel.
|
| + if (!IsInspectedBrowserPopup() &&
|
| + FindInspectedBrowserAndTabIndex(&inspected_browser,
|
| + &inspected_tab_index)) {
|
| + BrowserWindow* inspected_window = inspected_browser->window();
|
| + web_contents_->SetDelegate(this);
|
| + inspected_window->UpdateDevTools();
|
| + web_contents_->GetView()->SetInitialFocus();
|
| + inspected_window->Show();
|
| + TabStripModel* tab_strip_model = inspected_browser->tab_strip_model();
|
| + tab_strip_model->ActivateTabAt(inspected_tab_index, true);
|
| + PrefsTabHelper::CreateForWebContents(web_contents_);
|
| + GetRenderViewHost()->SyncRendererPrefs();
|
| + ScheduleAction(action);
|
| + return;
|
| + } else {
|
| + // Sometimes we don't know where to dock. Stay undocked.
|
| + dock_side_ = DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| + }
|
| + }
|
|
|
| -RenderViewHost* DevToolsWindow::GetRenderViewHost() {
|
| - return web_contents_->GetRenderViewHost();
|
| -}
|
| + // Avoid consecutive window switching if the devtools window has been opened
|
| + // and the Inspect Element shortcut is pressed in the inspected tab.
|
| + bool should_show_window =
|
| + !browser_ || action != DEVTOOLS_TOGGLE_ACTION_INSPECT;
|
|
|
| -void DevToolsWindow::CreateDevToolsBrowser() {
|
| - std::string wp_key = GetDevToolsWindowPlacementPrefKey();
|
| - PrefService* prefs = profile_->GetPrefs();
|
| - const DictionaryValue* wp_pref = prefs->GetDictionary(wp_key.c_str());
|
| - if (!wp_pref || wp_pref->empty()) {
|
| - DictionaryPrefUpdate update(prefs, wp_key.c_str());
|
| - DictionaryValue* defaults = update.Get();
|
| - defaults->SetInteger("left", 100);
|
| - defaults->SetInteger("top", 100);
|
| - defaults->SetInteger("right", 740);
|
| - defaults->SetInteger("bottom", 740);
|
| - defaults->SetBoolean("maximized", false);
|
| - defaults->SetBoolean("always_on_top", false);
|
| + if (!browser_)
|
| + CreateDevToolsBrowser();
|
| +
|
| + if (should_show_window) {
|
| + browser_->window()->Show();
|
| + web_contents_->GetView()->SetInitialFocus();
|
| }
|
|
|
| - chrome::HostDesktopType host_desktop_type =
|
| - chrome::GetHostDesktopTypeForNativeView(
|
| - web_contents_->GetView()->GetNativeView());
|
| -
|
| - browser_ = new Browser(Browser::CreateParams::CreateForDevTools(
|
| - profile_, host_desktop_type));
|
| - browser_->tab_strip_model()->AddWebContents(
|
| - web_contents_, -1, content::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
| - TabStripModel::ADD_ACTIVE);
|
| - GetRenderViewHost()->SyncRendererPrefs();
|
| + ScheduleAction(action);
|
| }
|
|
|
| -bool DevToolsWindow::FindInspectedBrowserAndTabIndex(Browser** browser,
|
| - int* tab) {
|
| - content::WebContents* inspected_web_contents = GetInspectedWebContents();
|
| - if (!inspected_web_contents)
|
| - return false;
|
| +DevToolsWindow::DevToolsWindow(Profile* profile,
|
| + const GURL& url,
|
| + RenderViewHost* inspected_rvh,
|
| + DevToolsDockSide dock_side)
|
| + : profile_(profile),
|
| + browser_(NULL),
|
| + dock_side_(dock_side),
|
| + is_loaded_(false),
|
| + action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW),
|
| + weak_factory_(this),
|
| + width_(-1),
|
| + height_(-1),
|
| + dock_side_before_minimized_(dock_side) {
|
| + web_contents_ = WebContents::Create(WebContents::CreateParams(profile));
|
| + frontend_contents_observer_.reset(
|
| + new FrontendWebContentsObserver(web_contents_));
|
|
|
| - for (chrome::BrowserIterator it; !it.done(); it.Next()) {
|
| - int tab_index = it->tab_strip_model()->GetIndexOfWebContents(
|
| - inspected_web_contents);
|
| - if (tab_index != TabStripModel::kNoTab) {
|
| - *browser = *it;
|
| - *tab = tab_index;
|
| - return true;
|
| - }
|
| - }
|
| - return false;
|
| -}
|
| + web_contents_->GetController().LoadURL(url, content::Referrer(),
|
| + content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
|
|
|
| -BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() {
|
| - Browser* browser = NULL;
|
| - int tab;
|
| - return FindInspectedBrowserAndTabIndex(&browser, &tab) ?
|
| - browser->window() : NULL;
|
| -}
|
| + frontend_host_.reset(
|
| + DevToolsClientHost::CreateDevToolsFrontendHost(web_contents_, this));
|
| + file_helper_.reset(new DevToolsFileHelper(web_contents_, profile));
|
|
|
| -bool DevToolsWindow::IsInspectedBrowserPopup() {
|
| - Browser* browser = NULL;
|
| - int tab;
|
| - if (!FindInspectedBrowserAndTabIndex(&browser, &tab))
|
| - return false;
|
| + g_instances.Get().push_back(this);
|
| + // Wipe out page icon so that the default application icon is used.
|
| + NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
|
| + entry->GetFavicon().image = gfx::Image();
|
| + entry->GetFavicon().valid = true;
|
|
|
| - return browser->is_type_popup();
|
| + // Register on-load actions.
|
| + registrar_.Add(
|
| + this,
|
| + content::NOTIFICATION_LOAD_STOP,
|
| + content::Source<NavigationController>(&web_contents_->GetController()));
|
| + registrar_.Add(
|
| + this,
|
| + chrome::NOTIFICATION_TAB_CLOSING,
|
| + content::Source<NavigationController>(&web_contents_->GetController()));
|
| + registrar_.Add(
|
| + this,
|
| + chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
|
| + content::Source<ThemeService>(
|
| + ThemeServiceFactory::GetForProfile(profile_)));
|
| + // There is no inspected_rvh in case of shared workers.
|
| + if (inspected_rvh)
|
| + inspected_contents_observer_.reset(new InspectedWebContentsObserver(
|
| + WebContents::FromRenderViewHost(inspected_rvh)));
|
| }
|
|
|
| -void DevToolsWindow::UpdateFrontendDockSide() {
|
| - base::StringValue dock_side(SideToString(dock_side_));
|
| - CallClientFunction("InspectorFrontendAPI.setDockSide", &dock_side);
|
| - base::FundamentalValue docked(IsDocked());
|
| - CallClientFunction("InspectorFrontendAPI.setAttachedWindow", &docked);
|
| +// static
|
| +DevToolsWindow* DevToolsWindow::Create(
|
| + Profile* profile,
|
| + const GURL& frontend_url,
|
| + RenderViewHost* inspected_rvh,
|
| + DevToolsDockSide dock_side,
|
| + bool shared_worker_frontend) {
|
| + // Create WebContents with devtools.
|
| + GURL url = GetDevToolsURL(profile, frontend_url, dock_side,
|
| + shared_worker_frontend);
|
| + return new DevToolsWindow(profile, url, inspected_rvh, dock_side);
|
| }
|
|
|
| +// static
|
| +GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
|
| + const GURL& base_url,
|
| + DevToolsDockSide dock_side,
|
| + bool shared_worker_frontend) {
|
| + ThemeService* tp = ThemeServiceFactory::GetForProfile(profile);
|
| + CHECK(tp);
|
|
|
| -void DevToolsWindow::AddDevToolsExtensionsToClient() {
|
| - content::WebContents* inspected_web_contents = GetInspectedWebContents();
|
| - if (inspected_web_contents) {
|
| - SessionTabHelper* session_tab_helper =
|
| - SessionTabHelper::FromWebContents(inspected_web_contents);
|
| - if (session_tab_helper) {
|
| - base::FundamentalValue tabId(session_tab_helper->session_id().id());
|
| - CallClientFunction("WebInspector.setInspectedTabId", &tabId);
|
| - }
|
| - }
|
| - ListValue results;
|
| - Profile* profile =
|
| - Profile::FromBrowserContext(web_contents_->GetBrowserContext());
|
| - const ExtensionService* extension_service = extensions::ExtensionSystem::Get(
|
| - profile->GetOriginalProfile())->extension_service();
|
| - if (!extension_service)
|
| - return;
|
| + SkColor color_toolbar =
|
| + tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
|
| + SkColor color_tab_text =
|
| + tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
|
|
|
| - const ExtensionSet* extensions = extension_service->extensions();
|
| + const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
| + bool experiments_enabled =
|
| + command_line.HasSwitch(switches::kEnableDevToolsExperiments);
|
|
|
| - for (ExtensionSet::const_iterator extension = extensions->begin();
|
| - extension != extensions->end(); ++extension) {
|
| - if (extensions::ManifestURL::GetDevToolsPage(extension->get()).is_empty())
|
| - continue;
|
| - DictionaryValue* extension_info = new DictionaryValue();
|
| - extension_info->Set(
|
| - "startPage",
|
| - new StringValue(
|
| - extensions::ManifestURL::GetDevToolsPage(extension->get()).spec()));
|
| - extension_info->Set("name", new StringValue((*extension)->name()));
|
| - bool allow_experimental = (*extension)->HasAPIPermission(
|
| - extensions::APIPermission::kExperimental);
|
| - extension_info->Set("exposeExperimentalAPIs",
|
| - new base::FundamentalValue(allow_experimental));
|
| - results.Append(extension_info);
|
| + std::string frontend_url = base_url.is_empty() ?
|
| + chrome::kChromeUIDevToolsURL : base_url.spec();
|
| + std::string params_separator =
|
| + frontend_url.find("?") == std::string::npos ? "?" : "&";
|
| + std::string url_string = base::StringPrintf("%s%s"
|
| + "dockSide=%s&toolbarColor=%s&textColor=%s%s%s",
|
| + frontend_url.c_str(),
|
| + params_separator.c_str(),
|
| + SideToString(dock_side).c_str(),
|
| + SkColorToRGBAString(color_toolbar).c_str(),
|
| + SkColorToRGBAString(color_tab_text).c_str(),
|
| + shared_worker_frontend ? "&isSharedWorker=true" : "",
|
| + experiments_enabled ? "&experiments=true" : "");
|
| + return GURL(url_string);
|
| +}
|
| +
|
| +// static
|
| +DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
|
| + DevToolsAgentHost* agent_host) {
|
| + DevToolsManager* manager = DevToolsManager::GetInstance();
|
| + DevToolsWindowList& instances = g_instances.Get();
|
| + for (DevToolsWindowList::iterator it = instances.begin();
|
| + it != instances.end(); ++it) {
|
| + if (manager->GetDevToolsAgentHostFor((*it)->frontend_host_.get()) ==
|
| + agent_host)
|
| + return *it;
|
| }
|
| - CallClientFunction("WebInspector.addExtensions", &results);
|
| + return NULL;
|
| }
|
|
|
| -WebContents* DevToolsWindow::OpenURLFromTab(WebContents* source,
|
| - const OpenURLParams& params) {
|
| - if (!params.url.SchemeIs(chrome::kChromeDevToolsScheme)) {
|
| - content::WebContents* inspected_web_contents = GetInspectedWebContents();
|
| - if (inspected_web_contents)
|
| - return inspected_web_contents->OpenURL(params);
|
| +// static
|
| +DevToolsWindow* DevToolsWindow::AsDevToolsWindow(RenderViewHost* window_rvh) {
|
| + if (g_instances == NULL)
|
| return NULL;
|
| + DevToolsWindowList& instances = g_instances.Get();
|
| + for (DevToolsWindowList::iterator it = instances.begin();
|
| + it != instances.end(); ++it) {
|
| + if ((*it)->web_contents_->GetRenderViewHost() == window_rvh)
|
| + return *it;
|
| }
|
| + return NULL;
|
| +}
|
|
|
| - DevToolsManager* manager = DevToolsManager::GetInstance();
|
| - scoped_refptr<DevToolsAgentHost> agent_host(
|
| - manager->GetDevToolsAgentHostFor(frontend_host_.get()));
|
| - if (!agent_host.get())
|
| - return NULL;
|
| - manager->ClientHostClosing(frontend_host_.get());
|
| - manager->RegisterDevToolsClientHostFor(agent_host.get(),
|
| - frontend_host_.get());
|
| +// static
|
| +DevToolsDockSide DevToolsWindow::GetDockSideFromPrefs(Profile* profile) {
|
| + std::string dock_side =
|
| + profile->GetPrefs()->GetString(prefs::kDevToolsDockSide);
|
|
|
| - chrome::NavigateParams nav_params(profile_, params.url, params.transition);
|
| - FillNavigateParamsFromOpenURLParams(&nav_params, params);
|
| - nav_params.source_contents = source;
|
| - nav_params.tabstrip_add_types = TabStripModel::ADD_NONE;
|
| - nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
|
| - nav_params.user_gesture = params.user_gesture;
|
| - chrome::Navigate(&nav_params);
|
| - return nav_params.target_contents;
|
| + // Migrate prefs
|
| + if (dock_side == kOldPrefBottom || dock_side == kOldPrefRight) {
|
| + bool docked = profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked);
|
| + if (dock_side == kOldPrefBottom)
|
| + return docked ? DEVTOOLS_DOCK_SIDE_BOTTOM : DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| + else
|
| + return docked ? DEVTOOLS_DOCK_SIDE_RIGHT : DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| + }
|
| +
|
| + if (dock_side == kPrefUndocked)
|
| + return DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| + else if (dock_side == kPrefRight)
|
| + return DEVTOOLS_DOCK_SIDE_RIGHT;
|
| + // Default to docked to bottom
|
| + return DEVTOOLS_DOCK_SIDE_BOTTOM;
|
| }
|
|
|
| -void DevToolsWindow::CallClientFunction(const std::string& function_name,
|
| - const Value* arg1,
|
| - const Value* arg2) {
|
| - std::string params;
|
| - if (arg1) {
|
| - std::string json;
|
| - base::JSONWriter::Write(arg1, &json);
|
| - params.append(json);
|
| - if (arg2) {
|
| - base::JSONWriter::Write(arg2, &json);
|
| - params.append(", " + json);
|
| - }
|
| +// static
|
| +std::string DevToolsWindow::SideToString(DevToolsDockSide dock_side) {
|
| + std::string dock_side_string;
|
| + switch (dock_side) {
|
| + case DEVTOOLS_DOCK_SIDE_UNDOCKED: return kDockSideUndocked;
|
| + case DEVTOOLS_DOCK_SIDE_RIGHT: return kDockSideRight;
|
| + case DEVTOOLS_DOCK_SIDE_BOTTOM: return kDockSideBottom;
|
| + case DEVTOOLS_DOCK_SIDE_MINIMIZED: return kDockSideMinimized;
|
| }
|
| - string16 javascript = ASCIIToUTF16(function_name + "(" + params + ");");
|
| - web_contents_->GetRenderViewHost()->
|
| - ExecuteJavascriptInWebFrame(string16(), javascript);
|
| + return kDockSideUndocked;
|
| }
|
|
|
| +// static
|
| +DevToolsDockSide DevToolsWindow::SideFromString(
|
| + const std::string& dock_side) {
|
| + if (dock_side == kDockSideRight)
|
| + return DEVTOOLS_DOCK_SIDE_RIGHT;
|
| + if (dock_side == kDockSideBottom)
|
| + return DEVTOOLS_DOCK_SIDE_BOTTOM;
|
| + if (dock_side == kDockSideMinimized)
|
| + return DEVTOOLS_DOCK_SIDE_MINIMIZED;
|
| + return DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| +}
|
| +
|
| void DevToolsWindow::Observe(int type,
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) {
|
| @@ -686,87 +708,34 @@
|
| }
|
| }
|
|
|
| -void DevToolsWindow::ScheduleAction(DevToolsToggleAction action) {
|
| - action_on_load_ = action;
|
| - if (is_loaded_)
|
| - DoAction();
|
| -}
|
| -
|
| -void DevToolsWindow::DoAction() {
|
| - UpdateFrontendDockSide();
|
| - switch (action_on_load_) {
|
| - case DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE:
|
| - CallClientFunction("InspectorFrontendAPI.showConsole", NULL);
|
| - break;
|
| - case DEVTOOLS_TOGGLE_ACTION_INSPECT:
|
| - CallClientFunction("InspectorFrontendAPI.enterInspectElementMode", NULL);
|
| - case DEVTOOLS_TOGGLE_ACTION_SHOW:
|
| - case DEVTOOLS_TOGGLE_ACTION_TOGGLE:
|
| - // Do nothing.
|
| - break;
|
| - default:
|
| - NOTREACHED();
|
| +WebContents* DevToolsWindow::OpenURLFromTab(WebContents* source,
|
| + const OpenURLParams& params) {
|
| + if (!params.url.SchemeIs(chrome::kChromeDevToolsScheme)) {
|
| + content::WebContents* inspected_web_contents = GetInspectedWebContents();
|
| + if (inspected_web_contents)
|
| + return inspected_web_contents->OpenURL(params);
|
| + return NULL;
|
| }
|
| - action_on_load_ = DEVTOOLS_TOGGLE_ACTION_SHOW;
|
| -}
|
|
|
| -std::string SkColorToRGBAString(SkColor color) {
|
| - // We convert the alpha using DoubleToString because StringPrintf will use
|
| - // locale specific formatters (e.g., use , instead of . in German).
|
| - return base::StringPrintf("rgba(%d,%d,%d,%s)", SkColorGetR(color),
|
| - SkColorGetG(color), SkColorGetB(color),
|
| - base::DoubleToString(SkColorGetA(color) / 255.0).c_str());
|
| -}
|
| + DevToolsManager* manager = DevToolsManager::GetInstance();
|
| + scoped_refptr<DevToolsAgentHost> agent_host(
|
| + manager->GetDevToolsAgentHostFor(frontend_host_.get()));
|
| + if (!agent_host.get())
|
| + return NULL;
|
| + manager->ClientHostClosing(frontend_host_.get());
|
| + manager->RegisterDevToolsClientHostFor(agent_host.get(),
|
| + frontend_host_.get());
|
|
|
| -// static
|
| -GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
|
| - const GURL& base_url,
|
| - DevToolsDockSide dock_side,
|
| - bool shared_worker_frontend) {
|
| - ThemeService* tp = ThemeServiceFactory::GetForProfile(profile);
|
| - CHECK(tp);
|
| -
|
| - SkColor color_toolbar =
|
| - tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
|
| - SkColor color_tab_text =
|
| - tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
|
| -
|
| - const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
| - bool experiments_enabled =
|
| - command_line.HasSwitch(switches::kEnableDevToolsExperiments);
|
| -
|
| - std::string frontend_url = base_url.is_empty() ?
|
| - chrome::kChromeUIDevToolsURL : base_url.spec();
|
| - std::string params_separator =
|
| - frontend_url.find("?") == std::string::npos ? "?" : "&";
|
| - std::string url_string = base::StringPrintf("%s%s"
|
| - "dockSide=%s&toolbarColor=%s&textColor=%s%s%s",
|
| - frontend_url.c_str(),
|
| - params_separator.c_str(),
|
| - SideToString(dock_side).c_str(),
|
| - SkColorToRGBAString(color_toolbar).c_str(),
|
| - SkColorToRGBAString(color_tab_text).c_str(),
|
| - shared_worker_frontend ? "&isSharedWorker=true" : "",
|
| - experiments_enabled ? "&experiments=true" : "");
|
| - return GURL(url_string);
|
| + chrome::NavigateParams nav_params(profile_, params.url, params.transition);
|
| + FillNavigateParamsFromOpenURLParams(&nav_params, params);
|
| + nav_params.source_contents = source;
|
| + nav_params.tabstrip_add_types = TabStripModel::ADD_NONE;
|
| + nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
|
| + nav_params.user_gesture = params.user_gesture;
|
| + chrome::Navigate(&nav_params);
|
| + return nav_params.target_contents;
|
| }
|
|
|
| -void DevToolsWindow::UpdateTheme() {
|
| - ThemeService* tp = ThemeServiceFactory::GetForProfile(profile_);
|
| - CHECK(tp);
|
| -
|
| - SkColor color_toolbar =
|
| - tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
|
| - SkColor color_tab_text =
|
| - tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
|
| - std::string command = base::StringPrintf(
|
| - "InspectorFrontendAPI.setToolbarColors(\"%s\", \"%s\")",
|
| - SkColorToRGBAString(color_toolbar).c_str(),
|
| - SkColorToRGBAString(color_tab_text).c_str());
|
| - web_contents_->GetRenderViewHost()->
|
| - ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(command));
|
| -}
|
| -
|
| void DevToolsWindow::AddNewContents(WebContents* source,
|
| WebContents* new_contents,
|
| WindowOpenDisposition disposition,
|
| @@ -781,6 +750,9 @@
|
| }
|
| }
|
|
|
| +void DevToolsWindow::CloseContents(content::WebContents* source) {
|
| +}
|
| +
|
| bool DevToolsWindow::PreHandleKeyboardEvent(
|
| WebContents* source,
|
| const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
|
| @@ -806,66 +778,33 @@
|
| }
|
| }
|
|
|
| -// static
|
| -DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
|
| - RenderViewHost* inspected_rvh,
|
| - bool force_open,
|
| - DevToolsToggleAction action) {
|
| - scoped_refptr<DevToolsAgentHost> agent(
|
| - DevToolsAgentHost::GetOrCreateFor(inspected_rvh));
|
| - DevToolsManager* manager = DevToolsManager::GetInstance();
|
| - DevToolsWindow* window = FindDevToolsWindow(agent.get());
|
| - bool do_open = force_open;
|
| - if (!window) {
|
| - Profile* profile = Profile::FromBrowserContext(
|
| - inspected_rvh->GetProcess()->GetBrowserContext());
|
| - DevToolsDockSide dock_side = GetDockSideFromPrefs(profile);
|
| - window = Create(profile, GURL(), inspected_rvh, dock_side, false);
|
| - manager->RegisterDevToolsClientHostFor(agent.get(),
|
| - window->frontend_host_.get());
|
| - do_open = true;
|
| +content::JavaScriptDialogManager* DevToolsWindow::GetJavaScriptDialogManager() {
|
| + content::WebContents* inspected_web_contents = GetInspectedWebContents();
|
| + if (inspected_web_contents && inspected_web_contents->GetDelegate()) {
|
| + return inspected_web_contents->GetDelegate()->
|
| + GetJavaScriptDialogManager();
|
| }
|
| + return content::WebContentsDelegate::GetJavaScriptDialogManager();
|
| +}
|
|
|
| - // Update toolbar to reflect DevTools changes.
|
| - window->UpdateBrowserToolbar();
|
| -
|
| - // If window is docked and visible, we hide it on toggle. If window is
|
| - // undocked, we show (activate) it. If window is minimized, we maximize it.
|
| - if (window->dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED)
|
| - window->Restore();
|
| - else if (!window->IsDocked() || do_open)
|
| - window->Show(action);
|
| - else
|
| - window->CloseWindow();
|
| -
|
| - return window;
|
| +content::ColorChooser* DevToolsWindow::OpenColorChooser(
|
| + WebContents* web_contents, SkColor initial_color) {
|
| + return chrome::ShowColorChooser(web_contents, initial_color);
|
| }
|
|
|
| -// static
|
| -DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
|
| - DevToolsAgentHost* agent_host) {
|
| - DevToolsManager* manager = DevToolsManager::GetInstance();
|
| - DevToolsWindowList& instances = g_instances.Get();
|
| - for (DevToolsWindowList::iterator it = instances.begin();
|
| - it != instances.end(); ++it) {
|
| - if (manager->GetDevToolsAgentHostFor((*it)->frontend_host_.get()) ==
|
| - agent_host)
|
| - return *it;
|
| - }
|
| - return NULL;
|
| +void DevToolsWindow::RunFileChooser(WebContents* web_contents,
|
| + const FileChooserParams& params) {
|
| + FileSelectHelper::RunFileChooser(web_contents, params);
|
| }
|
|
|
| -// static
|
| -DevToolsWindow* DevToolsWindow::AsDevToolsWindow(RenderViewHost* window_rvh) {
|
| - if (g_instances == NULL)
|
| - return NULL;
|
| - DevToolsWindowList& instances = g_instances.Get();
|
| - for (DevToolsWindowList::iterator it = instances.begin();
|
| - it != instances.end(); ++it) {
|
| - if ((*it)->web_contents_->GetRenderViewHost() == window_rvh)
|
| - return *it;
|
| +void DevToolsWindow::WebContentsFocused(WebContents* contents) {
|
| + Browser* inspected_browser = NULL;
|
| + int inspected_tab_index = -1;
|
| +
|
| + if (IsDocked() && FindInspectedBrowserAndTabIndex(&inspected_browser,
|
| + &inspected_tab_index)) {
|
| + inspected_browser->window()->WebContentsFocused(contents);
|
| }
|
| - return NULL;
|
| }
|
|
|
| void DevToolsWindow::ActivateWindow() {
|
| @@ -954,11 +893,6 @@
|
| Show(DEVTOOLS_TOGGLE_ACTION_SHOW);
|
| }
|
|
|
| -void DevToolsWindow::Restore() {
|
| - if (dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED)
|
| - SetDockSide(SideToString(dock_side_before_minimized_));
|
| -}
|
| -
|
| void DevToolsWindow::OpenInNewTab(const std::string& url) {
|
| OpenURLParams params(GURL(url),
|
| content::Referrer(),
|
| @@ -1006,19 +940,6 @@
|
| url));
|
| }
|
|
|
| -namespace {
|
| -
|
| -DictionaryValue* CreateFileSystemValue(
|
| - DevToolsFileHelper::FileSystem file_system) {
|
| - DictionaryValue* file_system_value = new DictionaryValue();
|
| - file_system_value->SetString("fileSystemName", file_system.file_system_name);
|
| - file_system_value->SetString("rootURL", file_system.root_url);
|
| - file_system_value->SetString("fileSystemPath", file_system.file_system_path);
|
| - return file_system_value;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| void DevToolsWindow::RequestFileSystems() {
|
| CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme));
|
| file_helper_->RequestFileSystems(
|
| @@ -1092,35 +1013,191 @@
|
| }
|
| }
|
|
|
| -content::JavaScriptDialogManager* DevToolsWindow::GetJavaScriptDialogManager() {
|
| +void DevToolsWindow::CreateDevToolsBrowser() {
|
| + std::string wp_key = GetDevToolsWindowPlacementPrefKey();
|
| + PrefService* prefs = profile_->GetPrefs();
|
| + const DictionaryValue* wp_pref = prefs->GetDictionary(wp_key.c_str());
|
| + if (!wp_pref || wp_pref->empty()) {
|
| + DictionaryPrefUpdate update(prefs, wp_key.c_str());
|
| + DictionaryValue* defaults = update.Get();
|
| + defaults->SetInteger("left", 100);
|
| + defaults->SetInteger("top", 100);
|
| + defaults->SetInteger("right", 740);
|
| + defaults->SetInteger("bottom", 740);
|
| + defaults->SetBoolean("maximized", false);
|
| + defaults->SetBoolean("always_on_top", false);
|
| + }
|
| +
|
| + chrome::HostDesktopType host_desktop_type =
|
| + chrome::GetHostDesktopTypeForNativeView(
|
| + web_contents_->GetView()->GetNativeView());
|
| +
|
| + browser_ = new Browser(Browser::CreateParams::CreateForDevTools(
|
| + profile_, host_desktop_type));
|
| + browser_->tab_strip_model()->AddWebContents(
|
| + web_contents_, -1, content::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
| + TabStripModel::ADD_ACTIVE);
|
| + GetRenderViewHost()->SyncRendererPrefs();
|
| +}
|
| +
|
| +bool DevToolsWindow::FindInspectedBrowserAndTabIndex(Browser** browser,
|
| + int* tab) {
|
| content::WebContents* inspected_web_contents = GetInspectedWebContents();
|
| - if (inspected_web_contents && inspected_web_contents->GetDelegate()) {
|
| - return inspected_web_contents->GetDelegate()->
|
| - GetJavaScriptDialogManager();
|
| + if (!inspected_web_contents)
|
| + return false;
|
| +
|
| + for (chrome::BrowserIterator it; !it.done(); it.Next()) {
|
| + int tab_index = it->tab_strip_model()->GetIndexOfWebContents(
|
| + inspected_web_contents);
|
| + if (tab_index != TabStripModel::kNoTab) {
|
| + *browser = *it;
|
| + *tab = tab_index;
|
| + return true;
|
| + }
|
| }
|
| - return content::WebContentsDelegate::GetJavaScriptDialogManager();
|
| + return false;
|
| }
|
|
|
| -content::ColorChooser* DevToolsWindow::OpenColorChooser(
|
| - WebContents* web_contents, SkColor initial_color) {
|
| - return chrome::ShowColorChooser(web_contents, initial_color);
|
| +BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() {
|
| + Browser* browser = NULL;
|
| + int tab;
|
| + return FindInspectedBrowserAndTabIndex(&browser, &tab) ?
|
| + browser->window() : NULL;
|
| }
|
|
|
| -void DevToolsWindow::RunFileChooser(WebContents* web_contents,
|
| - const FileChooserParams& params) {
|
| - FileSelectHelper::RunFileChooser(web_contents, params);
|
| +bool DevToolsWindow::IsInspectedBrowserPopup() {
|
| + Browser* browser = NULL;
|
| + int tab;
|
| + if (!FindInspectedBrowserAndTabIndex(&browser, &tab))
|
| + return false;
|
| +
|
| + return browser->is_type_popup();
|
| }
|
|
|
| -void DevToolsWindow::WebContentsFocused(WebContents* contents) {
|
| - Browser* inspected_browser = NULL;
|
| - int inspected_tab_index = -1;
|
| +void DevToolsWindow::UpdateFrontendDockSide() {
|
| + base::StringValue dock_side(SideToString(dock_side_));
|
| + CallClientFunction("InspectorFrontendAPI.setDockSide", &dock_side);
|
| + base::FundamentalValue docked(IsDocked());
|
| + CallClientFunction("InspectorFrontendAPI.setAttachedWindow", &docked);
|
| +}
|
|
|
| - if (IsDocked() && FindInspectedBrowserAndTabIndex(&inspected_browser,
|
| - &inspected_tab_index)) {
|
| - inspected_browser->window()->WebContentsFocused(contents);
|
| +void DevToolsWindow::Hide() {
|
| + if (IsDocked()) {
|
| + // Update dev tools to reflect removed dev tools window.
|
| + BrowserWindow* inspected_window = GetInspectedBrowserWindow();
|
| + if (inspected_window)
|
| + inspected_window->UpdateDevTools();
|
| + // In case of docked web_contents_, we own it so delete here.
|
| + delete web_contents_;
|
| +
|
| + delete this;
|
| + } else {
|
| + // First, initiate self-destruct to free all the registrars.
|
| + // Then close all tabs. Browser will take care of deleting web_contents_
|
| + // for us.
|
| + Browser* browser = browser_;
|
| + delete this;
|
| + browser->tab_strip_model()->CloseAllTabs();
|
| }
|
| }
|
|
|
| +void DevToolsWindow::ScheduleAction(DevToolsToggleAction action) {
|
| + action_on_load_ = action;
|
| + if (is_loaded_)
|
| + DoAction();
|
| +}
|
| +
|
| +void DevToolsWindow::DoAction() {
|
| + UpdateFrontendDockSide();
|
| + switch (action_on_load_) {
|
| + case DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE:
|
| + CallClientFunction("InspectorFrontendAPI.showConsole", NULL);
|
| + break;
|
| + case DEVTOOLS_TOGGLE_ACTION_INSPECT:
|
| + CallClientFunction("InspectorFrontendAPI.enterInspectElementMode", NULL);
|
| + case DEVTOOLS_TOGGLE_ACTION_SHOW:
|
| + case DEVTOOLS_TOGGLE_ACTION_TOGGLE:
|
| + // Do nothing.
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| + action_on_load_ = DEVTOOLS_TOGGLE_ACTION_SHOW;
|
| +}
|
| +
|
| +void DevToolsWindow::UpdateTheme() {
|
| + ThemeService* tp = ThemeServiceFactory::GetForProfile(profile_);
|
| + CHECK(tp);
|
| +
|
| + SkColor color_toolbar =
|
| + tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
|
| + SkColor color_tab_text =
|
| + tp->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
|
| + std::string command = base::StringPrintf(
|
| + "InspectorFrontendAPI.setToolbarColors(\"%s\", \"%s\")",
|
| + SkColorToRGBAString(color_toolbar).c_str(),
|
| + SkColorToRGBAString(color_tab_text).c_str());
|
| + web_contents_->GetRenderViewHost()->
|
| + ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(command));
|
| +}
|
| +
|
| +void DevToolsWindow::AddDevToolsExtensionsToClient() {
|
| + content::WebContents* inspected_web_contents = GetInspectedWebContents();
|
| + if (inspected_web_contents) {
|
| + SessionTabHelper* session_tab_helper =
|
| + SessionTabHelper::FromWebContents(inspected_web_contents);
|
| + if (session_tab_helper) {
|
| + base::FundamentalValue tabId(session_tab_helper->session_id().id());
|
| + CallClientFunction("WebInspector.setInspectedTabId", &tabId);
|
| + }
|
| + }
|
| + ListValue results;
|
| + Profile* profile =
|
| + Profile::FromBrowserContext(web_contents_->GetBrowserContext());
|
| + const ExtensionService* extension_service = extensions::ExtensionSystem::Get(
|
| + profile->GetOriginalProfile())->extension_service();
|
| + if (!extension_service)
|
| + return;
|
| +
|
| + const ExtensionSet* extensions = extension_service->extensions();
|
| +
|
| + for (ExtensionSet::const_iterator extension = extensions->begin();
|
| + extension != extensions->end(); ++extension) {
|
| + if (extensions::ManifestURL::GetDevToolsPage(extension->get()).is_empty())
|
| + continue;
|
| + DictionaryValue* extension_info = new DictionaryValue();
|
| + extension_info->Set(
|
| + "startPage",
|
| + new StringValue(
|
| + extensions::ManifestURL::GetDevToolsPage(extension->get()).spec()));
|
| + extension_info->Set("name", new StringValue((*extension)->name()));
|
| + bool allow_experimental = (*extension)->HasAPIPermission(
|
| + extensions::APIPermission::kExperimental);
|
| + extension_info->Set("exposeExperimentalAPIs",
|
| + new base::FundamentalValue(allow_experimental));
|
| + results.Append(extension_info);
|
| + }
|
| + CallClientFunction("WebInspector.addExtensions", &results);
|
| +}
|
| +
|
| +void DevToolsWindow::CallClientFunction(const std::string& function_name,
|
| + const Value* arg1,
|
| + const Value* arg2) {
|
| + std::string params;
|
| + if (arg1) {
|
| + std::string json;
|
| + base::JSONWriter::Write(arg1, &json);
|
| + params.append(json);
|
| + if (arg2) {
|
| + base::JSONWriter::Write(arg2, &json);
|
| + params.append(", " + json);
|
| + }
|
| + }
|
| + string16 javascript = ASCIIToUTF16(function_name + "(" + params + ");");
|
| + web_contents_->GetRenderViewHost()->
|
| + ExecuteJavascriptInWebFrame(string16(), javascript);
|
| +}
|
| +
|
| void DevToolsWindow::UpdateBrowserToolbar() {
|
| content::WebContents* inspected_web_contents = GetInspectedWebContents();
|
| if (!inspected_web_contents)
|
| @@ -1134,48 +1211,13 @@
|
| return dock_side_ != DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| }
|
|
|
| -// static
|
| -DevToolsDockSide DevToolsWindow::GetDockSideFromPrefs(Profile* profile) {
|
| - std::string dock_side =
|
| - profile->GetPrefs()->GetString(prefs::kDevToolsDockSide);
|
| -
|
| - // Migrate prefs
|
| - if (dock_side == kOldPrefBottom || dock_side == kOldPrefRight) {
|
| - bool docked = profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked);
|
| - if (dock_side == kOldPrefBottom)
|
| - return docked ? DEVTOOLS_DOCK_SIDE_BOTTOM : DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| - else
|
| - return docked ? DEVTOOLS_DOCK_SIDE_RIGHT : DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| - }
|
| -
|
| - if (dock_side == kPrefUndocked)
|
| - return DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| - else if (dock_side == kPrefRight)
|
| - return DEVTOOLS_DOCK_SIDE_RIGHT;
|
| - // Default to docked to bottom
|
| - return DEVTOOLS_DOCK_SIDE_BOTTOM;
|
| +void DevToolsWindow::Restore() {
|
| + if (dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED)
|
| + SetDockSide(SideToString(dock_side_before_minimized_));
|
| }
|
|
|
| -// static
|
| -std::string DevToolsWindow::SideToString(DevToolsDockSide dock_side) {
|
| - std::string dock_side_string;
|
| - switch (dock_side) {
|
| - case DEVTOOLS_DOCK_SIDE_UNDOCKED: return kDockSideUndocked;
|
| - case DEVTOOLS_DOCK_SIDE_RIGHT: return kDockSideRight;
|
| - case DEVTOOLS_DOCK_SIDE_BOTTOM: return kDockSideBottom;
|
| - case DEVTOOLS_DOCK_SIDE_MINIMIZED: return kDockSideMinimized;
|
| - }
|
| - return kDockSideUndocked;
|
| +content::WebContents* DevToolsWindow::GetInspectedWebContents() {
|
| + if (!inspected_contents_observer_)
|
| + return NULL;
|
| + return inspected_contents_observer_->web_contents();
|
| }
|
| -
|
| -// static
|
| -DevToolsDockSide DevToolsWindow::SideFromString(
|
| - const std::string& dock_side) {
|
| - if (dock_side == kDockSideRight)
|
| - return DEVTOOLS_DOCK_SIDE_RIGHT;
|
| - if (dock_side == kDockSideBottom)
|
| - return DEVTOOLS_DOCK_SIDE_BOTTOM;
|
| - if (dock_side == kDockSideMinimized)
|
| - return DEVTOOLS_DOCK_SIDE_MINIMIZED;
|
| - return DEVTOOLS_DOCK_SIDE_UNDOCKED;
|
| -}
|
|
|