OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/devtools/devtools_window.h" | 5 #include "chrome/browser/devtools/devtools_window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 b->tab_strip_model()->GetIndexOfWebContents(inspected_web_contents); | 83 b->tab_strip_model()->GetIndexOfWebContents(inspected_web_contents); |
84 if (tab_index != TabStripModel::kNoTab) { | 84 if (tab_index != TabStripModel::kNoTab) { |
85 *browser = b; | 85 *browser = b; |
86 *tab = tab_index; | 86 *tab = tab_index; |
87 return true; | 87 return true; |
88 } | 88 } |
89 } | 89 } |
90 return false; | 90 return false; |
91 } | 91 } |
92 | 92 |
| 93 void SetPreferencesFromJson(Profile* profile, const std::string& json) { |
| 94 base::DictionaryValue* dict = nullptr; |
| 95 std::unique_ptr<base::Value> parsed = base::JSONReader::Read(json); |
| 96 if (!parsed || !parsed->GetAsDictionary(&dict)) |
| 97 return; |
| 98 DictionaryPrefUpdate update(profile->GetPrefs(), prefs::kDevToolsPreferences); |
| 99 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 100 if (!it.value().IsType(base::Value::TYPE_STRING)) |
| 101 continue; |
| 102 update.Get()->SetWithoutPathExpansion( |
| 103 it.key(), it.value().CreateDeepCopy()); |
| 104 } |
| 105 } |
| 106 |
93 // DevToolsToolboxDelegate ---------------------------------------------------- | 107 // DevToolsToolboxDelegate ---------------------------------------------------- |
94 | 108 |
95 class DevToolsToolboxDelegate | 109 class DevToolsToolboxDelegate |
96 : public content::WebContentsObserver, | 110 : public content::WebContentsObserver, |
97 public content::WebContentsDelegate { | 111 public content::WebContentsDelegate { |
98 public: | 112 public: |
99 DevToolsToolboxDelegate( | 113 DevToolsToolboxDelegate( |
100 WebContents* toolbox_contents, | 114 WebContents* toolbox_contents, |
101 DevToolsWindow::ObserverWithAccessor* web_contents_observer); | 115 DevToolsWindow::ObserverWithAccessor* web_contents_observer); |
102 ~DevToolsToolboxDelegate() override; | 116 ~DevToolsToolboxDelegate() override; |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 &browser, &tab) || | 798 &browser, &tab) || |
785 browser->is_type_popup()) { | 799 browser->is_type_popup()) { |
786 can_dock = false; | 800 can_dock = false; |
787 } | 801 } |
788 } | 802 } |
789 | 803 |
790 // Create WebContents with devtools. | 804 // Create WebContents with devtools. |
791 GURL url(GetDevToolsURL(profile, frontend_url, | 805 GURL url(GetDevToolsURL(profile, frontend_url, |
792 shared_worker_frontend, | 806 shared_worker_frontend, |
793 remote_frontend, | 807 remote_frontend, |
794 can_dock, settings)); | 808 can_dock)); |
795 std::unique_ptr<WebContents> main_web_contents( | 809 std::unique_ptr<WebContents> main_web_contents( |
796 WebContents::Create(WebContents::CreateParams(profile))); | 810 WebContents::Create(WebContents::CreateParams(profile))); |
797 main_web_contents->GetController().LoadURL( | 811 main_web_contents->GetController().LoadURL( |
798 DecorateFrontendURL(url), content::Referrer(), | 812 DecorateFrontendURL(url), content::Referrer(), |
799 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 813 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
800 DevToolsUIBindings* bindings = | 814 DevToolsUIBindings* bindings = |
801 DevToolsUIBindings::ForWebContents(main_web_contents.get()); | 815 DevToolsUIBindings::ForWebContents(main_web_contents.get()); |
802 if (!bindings) | 816 if (!bindings) |
803 return nullptr; | 817 return nullptr; |
804 | 818 if (!settings.empty()) |
| 819 SetPreferencesFromJson(profile, settings); |
805 return new DevToolsWindow(profile, main_web_contents.release(), bindings, | 820 return new DevToolsWindow(profile, main_web_contents.release(), bindings, |
806 inspected_web_contents, can_dock); | 821 inspected_web_contents, can_dock); |
807 } | 822 } |
808 | 823 |
809 // static | 824 // static |
810 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, | 825 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, |
811 const GURL& base_url, | 826 const GURL& base_url, |
812 bool shared_worker_frontend, | 827 bool shared_worker_frontend, |
813 const std::string& remote_frontend, | 828 const std::string& remote_frontend, |
814 bool can_dock, | 829 bool can_dock) { |
815 const std::string& settings) { | |
816 // Compatibility errors are encoded with data urls, pass them | 830 // Compatibility errors are encoded with data urls, pass them |
817 // through with no decoration. | 831 // through with no decoration. |
818 if (base_url.SchemeIs("data")) | 832 if (base_url.SchemeIs("data")) |
819 return base_url; | 833 return base_url; |
820 | 834 |
821 std::string frontend_url( | 835 std::string frontend_url( |
822 !remote_frontend.empty() ? | 836 !remote_frontend.empty() ? |
823 remote_frontend : | 837 remote_frontend : |
824 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); | 838 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); |
825 std::string url_string( | 839 std::string url_string( |
826 frontend_url + | 840 frontend_url + |
827 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); | 841 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); |
828 if (shared_worker_frontend) | 842 if (shared_worker_frontend) |
829 url_string += "&isSharedWorker=true"; | 843 url_string += "&isSharedWorker=true"; |
830 if (remote_frontend.size()) { | 844 if (remote_frontend.size()) { |
831 url_string += "&remoteFrontend=true"; | 845 url_string += "&remoteFrontend=true"; |
832 } else { | 846 } else { |
833 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec(); | 847 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec(); |
834 } | 848 } |
835 if (can_dock) | 849 if (can_dock) |
836 url_string += "&can_dock=true"; | 850 url_string += "&can_dock=true"; |
837 if (settings.size()) | |
838 url_string += "&settings=" + settings; | |
839 return GURL(url_string); | 851 return GURL(url_string); |
840 } | 852 } |
841 | 853 |
842 // static | 854 // static |
843 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | 855 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
844 DevToolsAgentHost* agent_host) { | 856 DevToolsAgentHost* agent_host) { |
845 if (!agent_host || g_instances == NULL) | 857 if (!agent_host || g_instances == NULL) |
846 return NULL; | 858 return NULL; |
847 DevToolsWindows* instances = g_instances.Pointer(); | 859 DevToolsWindows* instances = g_instances.Pointer(); |
848 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 860 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { | 1315 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { |
1304 // Only route reload via front-end if the agent is attached. | 1316 // Only route reload via front-end if the agent is attached. |
1305 WebContents* wc = GetInspectedWebContents(); | 1317 WebContents* wc = GetInspectedWebContents(); |
1306 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) | 1318 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) |
1307 return false; | 1319 return false; |
1308 base::FundamentalValue bypass_cache_value(bypass_cache); | 1320 base::FundamentalValue bypass_cache_value(bypass_cache); |
1309 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", | 1321 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", |
1310 &bypass_cache_value, nullptr, nullptr); | 1322 &bypass_cache_value, nullptr, nullptr); |
1311 return true; | 1323 return true; |
1312 } | 1324 } |
OLD | NEW |