OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "extensions/browser/guest_view/extension_view/extension_view_guest.h" | 5 #include "extensions/browser/guest_view/extension_view/extension_view_guest.h" |
6 | 6 |
7 #include "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
8 #include "components/crx_file/id_util.h" | |
8 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
9 #include "content/public/common/result_codes.h" | 10 #include "content/public/common/result_codes.h" |
10 #include "extensions/browser/api/extensions_api_client.h" | 11 #include "extensions/browser/api/extensions_api_client.h" |
11 #include "extensions/browser/guest_view/extension_view/extension_view_constants. h" | 12 #include "extensions/browser/guest_view/extension_view/extension_view_constants. h" |
12 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
13 #include "extensions/common/extension_messages.h" | 14 #include "extensions/common/extension_messages.h" |
14 #include "extensions/strings/grit/extensions_strings.h" | 15 #include "extensions/strings/grit/extensions_strings.h" |
15 | 16 |
16 using content::WebContents; | 17 using content::WebContents; |
17 using namespace extensions::core_api; | 18 using namespace extensions::core_api; |
(...skipping 15 matching lines...) Expand all Loading... | |
33 } | 34 } |
34 | 35 |
35 // static | 36 // static |
36 extensions::GuestViewBase* ExtensionViewGuest::Create( | 37 extensions::GuestViewBase* ExtensionViewGuest::Create( |
37 content::WebContents* owner_web_contents) { | 38 content::WebContents* owner_web_contents) { |
38 return new ExtensionViewGuest(owner_web_contents); | 39 return new ExtensionViewGuest(owner_web_contents); |
39 } | 40 } |
40 | 41 |
41 void ExtensionViewGuest::NavigateGuest(const std::string& src, | 42 void ExtensionViewGuest::NavigateGuest(const std::string& src, |
42 bool force_navigation) { | 43 bool force_navigation) { |
43 if (src.empty()) | 44 GURL url(GetExtensionViewPage(src)); |
Fady Samuel
2015/02/16 19:26:28
I would follow WebViewGuest's code to navigate to
apacible
2015/02/17 18:31:25
Navigates to about:blank, and followed WebViewGues
Fady Samuel
2015/02/17 18:48:29
I would plumb loadcommit at least. loadcommit shou
| |
44 return; | |
45 | |
46 GURL url(src); | |
47 if (!url.is_valid() && !force_navigation && (url == view_page_)) | 45 if (!url.is_valid() && !force_navigation && (url == view_page_)) |
48 return; | 46 return; |
49 | 47 |
50 web_contents()->GetRenderProcessHost()->FilterURL(false, &url); | 48 web_contents()->GetRenderProcessHost()->FilterURL(false, &url); |
51 web_contents()->GetController().LoadURL(url, content::Referrer(), | 49 web_contents()->GetController().LoadURL(url, content::Referrer(), |
52 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 50 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
53 std::string()); | 51 std::string()); |
54 | 52 |
55 view_page_ = url; | 53 view_page_ = url; |
56 } | 54 } |
57 | 55 |
58 // GuestViewBase implementation. | 56 // GuestViewBase implementation. |
59 bool ExtensionViewGuest::CanRunInDetachedState() const { | 57 bool ExtensionViewGuest::CanRunInDetachedState() const { |
60 return true; | 58 return true; |
61 } | 59 } |
62 | 60 |
63 void ExtensionViewGuest::CreateWebContents( | 61 void ExtensionViewGuest::CreateWebContents( |
64 const base::DictionaryValue& create_params, | 62 const base::DictionaryValue& create_params, |
65 const WebContentsCreatedCallback& callback) { | 63 const WebContentsCreatedCallback& callback) { |
66 std::string str; | 64 // Gets the extension ID. |
67 if (!create_params.GetString(extensionview::kAttributeSrc, &str)) { | 65 std::string extension_id; |
66 create_params.GetString(extensionview::kAttributeExtension, &extension_id); | |
67 | |
68 if (!crx_file::id_util::IdIsValid(extension_id)) { | |
68 callback.Run(nullptr); | 69 callback.Run(nullptr); |
69 return; | 70 return; |
70 } | 71 } |
71 | 72 |
72 GURL source(str); | 73 // Gets the extension URL. |
73 if (!source.is_valid()) { | 74 GURL extension_url_from_id = |
Fady Samuel
2015/02/16 19:26:28
I would keep things as a GURL rather than as a str
apacible
2015/02/17 18:31:25
Changed extension_url_ to a GURL.
| |
75 extensions::Extension::GetBaseURLFromExtensionId(extension_id); | |
76 | |
77 if (!extension_url_from_id.is_valid()) { | |
78 callback.Run(nullptr); | |
79 return; | |
80 } | |
81 | |
82 extension_url_ = extension_url_from_id.spec(); | |
83 | |
84 // Get the src to build URL to render. | |
85 std::string src; | |
86 if (!create_params.GetString(extensionview::kAttributeSrc, &src)) { | |
87 callback.Run(nullptr); | |
88 return; | |
89 } | |
90 | |
91 view_page_ = GURL(GetExtensionViewPage(src)); | |
92 if (!view_page_.is_valid()) { | |
74 callback.Run(nullptr); | 93 callback.Run(nullptr); |
75 return; | 94 return; |
76 } | 95 } |
77 | 96 |
78 content::SiteInstance* view_site_instance = | 97 content::SiteInstance* view_site_instance = |
79 content::SiteInstance::CreateForURL(browser_context(), source); | 98 content::SiteInstance::CreateForURL(browser_context(), |
99 extension_url_from_id); | |
80 | 100 |
81 WebContents::CreateParams params(browser_context(), view_site_instance); | 101 WebContents::CreateParams params(browser_context(), view_site_instance); |
82 params.guest_delegate = this; | 102 params.guest_delegate = this; |
83 callback.Run(WebContents::Create(params)); | 103 callback.Run(WebContents::Create(params)); |
84 } | 104 } |
85 | 105 |
86 void ExtensionViewGuest::DidInitialize( | 106 void ExtensionViewGuest::DidInitialize( |
87 const base::DictionaryValue& create_params) { | 107 const base::DictionaryValue& create_params) { |
88 extension_function_dispatcher_.reset( | 108 extension_function_dispatcher_.reset( |
89 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); | 109 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 extension_function_dispatcher_->Dispatch(params, | 142 extension_function_dispatcher_->Dispatch(params, |
123 web_contents()->GetRenderViewHost()); | 143 web_contents()->GetRenderViewHost()); |
124 } | 144 } |
125 | 145 |
126 void ExtensionViewGuest::ApplyAttributes(const base::DictionaryValue& params) { | 146 void ExtensionViewGuest::ApplyAttributes(const base::DictionaryValue& params) { |
127 std::string src; | 147 std::string src; |
128 params.GetString(extensionview::kAttributeSrc, &src); | 148 params.GetString(extensionview::kAttributeSrc, &src); |
129 NavigateGuest(src, false /* force_navigation */); | 149 NavigateGuest(src, false /* force_navigation */); |
130 } | 150 } |
131 | 151 |
152 std::string ExtensionViewGuest::GetExtensionViewPage(std::string src) { | |
153 if (src.empty()) | |
154 return NULL; | |
155 | |
156 return extension_url_ + src; | |
Fady Samuel
2015/02/16 19:26:28
I would model this after WebViewGuest::ResolveURL.
apacible
2015/02/17 18:31:26
Done.
| |
157 } | |
158 | |
132 } // namespace extensions | 159 } // namespace extensions |
OLD | NEW |