Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/guestview/webview/webview_guest.h" | 5 #include "chrome/browser/guestview/webview/webview_guest.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 157 |
| 158 AttachWebViewHelpers(guest_web_contents); | 158 AttachWebViewHelpers(guest_web_contents); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // static | 161 // static |
| 162 WebViewGuest* WebViewGuest::From(int embedder_process_id, | 162 WebViewGuest* WebViewGuest::From(int embedder_process_id, |
| 163 int guest_instance_id) { | 163 int guest_instance_id) { |
| 164 GuestView* guest = GuestView::From(embedder_process_id, guest_instance_id); | 164 GuestView* guest = GuestView::From(embedder_process_id, guest_instance_id); |
| 165 if (!guest) | 165 if (!guest) |
| 166 return NULL; | 166 return NULL; |
| 167 return guest->AsWebView(); | 167 return guest->As<WebViewGuest>(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 // static | 170 // static |
| 171 WebViewGuest* WebViewGuest::FromWebContents(WebContents* contents) { | 171 WebViewGuest* WebViewGuest::FromWebContents(WebContents* contents) { |
| 172 GuestView* guest = GuestView::FromWebContents(contents); | 172 GuestView* guest = GuestView::FromWebContents(contents); |
| 173 return guest ? guest->AsWebView() : NULL; | 173 return guest ? guest->As<WebViewGuest>() : NULL; |
| 174 } | 174 } |
| 175 | 175 |
| 176 // static. | 176 // static. |
| 177 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | 177 int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| 178 WebViewGuest* guest = FromWebContents(contents); | 178 WebViewGuest* guest = FromWebContents(contents); |
| 179 if (!guest) | 179 if (!guest) |
| 180 return guestview::kInstanceIDNone; | 180 return guestview::kInstanceIDNone; |
| 181 | 181 |
| 182 return guest->view_instance_id(); | 182 return guest->view_instance_id(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // static | 185 // static |
| 186 GuestView::Type WebViewGuest::Type() { return GuestView::WEBVIEW; } | |
| 187 | |
| 188 // static | |
| 186 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, | 189 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, |
| 187 bool allow) { | 190 bool allow) { |
| 188 if (allow) { | 191 if (allow) { |
| 189 // Note that |allow| == true means the embedder explicitly allowed the | 192 // Note that |allow| == true means the embedder explicitly allowed the |
| 190 // request. For some requests they might still fail. An example of such | 193 // request. For some requests they might still fail. An example of such |
| 191 // scenario would be: an embedder allows geolocation request but doesn't | 194 // scenario would be: an embedder allows geolocation request but doesn't |
| 192 // have geolocation access on its own. | 195 // have geolocation access on its own. |
| 193 switch (info.permission_type) { | 196 switch (info.permission_type) { |
| 194 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: | 197 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: |
| 195 content::RecordAction( | 198 content::RecordAction( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 SetUserAgentOverride(user_agent_override); | 285 SetUserAgentOverride(user_agent_override); |
| 283 } else { | 286 } else { |
| 284 SetUserAgentOverride(""); | 287 SetUserAgentOverride(""); |
| 285 } | 288 } |
| 286 | 289 |
| 287 GuestView::Attach(embedder_web_contents, args); | 290 GuestView::Attach(embedder_web_contents, args); |
| 288 | 291 |
| 289 AddWebViewToExtensionRendererState(); | 292 AddWebViewToExtensionRendererState(); |
| 290 } | 293 } |
| 291 | 294 |
| 292 GuestView::Type WebViewGuest::GetViewType() const { | 295 GuestView::Type WebViewGuest::GetViewType() const { return Type(); } |
|
Fady Samuel
2014/04/16 02:47:44
I've been thinking. We can probably move GetViewTy
Xi Han
2014/04/16 13:33:32
Does it worth to introduce another layer just for
Xi Han
2014/04/16 17:42:19
As discussed offline, I will introduce a template
| |
| 293 return GuestView::WEBVIEW; | |
| 294 } | |
| 295 | |
| 296 WebViewGuest* WebViewGuest::AsWebView() { | |
| 297 return this; | |
| 298 } | |
| 299 | |
| 300 AdViewGuest* WebViewGuest::AsAdView() { | |
| 301 return NULL; | |
| 302 } | |
| 303 | 296 |
| 304 void WebViewGuest::AddMessageToConsole(int32 level, | 297 void WebViewGuest::AddMessageToConsole(int32 level, |
| 305 const base::string16& message, | 298 const base::string16& message, |
| 306 int32 line_no, | 299 int32 line_no, |
| 307 const base::string16& source_id) { | 300 const base::string16& source_id) { |
| 308 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 301 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 309 // Log levels are from base/logging.h: LogSeverity. | 302 // Log levels are from base/logging.h: LogSeverity. |
| 310 args->SetInteger(webview::kLevel, level); | 303 args->SetInteger(webview::kLevel, level); |
| 311 args->SetString(webview::kMessage, message); | 304 args->SetString(webview::kMessage, message); |
| 312 args->SetInteger(webview::kLine, line_no); | 305 args->SetInteger(webview::kLine, line_no); |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 const PermissionResponseCallback& callback, | 925 const PermissionResponseCallback& callback, |
| 933 BrowserPluginPermissionType permission_type, | 926 BrowserPluginPermissionType permission_type, |
| 934 bool allowed_by_default) | 927 bool allowed_by_default) |
| 935 : callback(callback), | 928 : callback(callback), |
| 936 permission_type(permission_type), | 929 permission_type(permission_type), |
| 937 allowed_by_default(allowed_by_default) { | 930 allowed_by_default(allowed_by_default) { |
| 938 } | 931 } |
| 939 | 932 |
| 940 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | 933 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
| 941 } | 934 } |
| OLD | NEW |