Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/guest_view/web_view/web_view_guest.h" | 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
| 6 | 6 |
| 7 #include "base/debug/stack_trace.h" | 7 #include "base/debug/stack_trace.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 item_value->SetInteger(webview::kMenuItemCommandId, | 303 item_value->SetInteger(webview::kMenuItemCommandId, |
| 304 menu_model.GetCommandIdAt(i)); | 304 menu_model.GetCommandIdAt(i)); |
| 305 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); | 305 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); |
| 306 items->Append(item_value); | 306 items->Append(item_value); |
| 307 } | 307 } |
| 308 return items.Pass(); | 308 return items.Pass(); |
| 309 } | 309 } |
| 310 | 310 |
| 311 void WebViewGuest::Attach(WebContents* embedder_web_contents, | 311 void WebViewGuest::Attach(WebContents* embedder_web_contents, |
| 312 const base::DictionaryValue& args) { | 312 const base::DictionaryValue& args) { |
| 313 std::string name; | |
| 314 args.GetString(webview::kName, &name); | |
| 315 if (name_.empty()) | |
|
lazyboy
2014/05/21 16:27:05
I think we had a note/comment here about which nam
Fady Samuel
2014/05/21 16:56:49
Done.
| |
| 316 name_ = name; | |
| 317 ReportFrameNameChange(name_); | |
| 318 | |
| 313 std::string user_agent_override; | 319 std::string user_agent_override; |
| 314 if (args.GetString(webview::kParameterUserAgentOverride, | 320 if (args.GetString(webview::kParameterUserAgentOverride, |
| 315 &user_agent_override)) { | 321 &user_agent_override)) { |
| 316 SetUserAgentOverride(user_agent_override); | 322 SetUserAgentOverride(user_agent_override); |
| 317 } else { | 323 } else { |
| 318 SetUserAgentOverride(""); | 324 SetUserAgentOverride(""); |
| 319 } | 325 } |
| 320 | 326 |
| 321 GuestViewBase::Attach(embedder_web_contents, args); | 327 GuestViewBase::Attach(embedder_web_contents, args); |
| 322 | 328 |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 864 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
| 859 if (!attached()) { | 865 if (!attached()) { |
| 860 // We cannot reload now because all resource loads are suspended until | 866 // We cannot reload now because all resource loads are suspended until |
| 861 // attachment. | 867 // attachment. |
| 862 pending_reload_on_attachment_ = true; | 868 pending_reload_on_attachment_ = true; |
| 863 return; | 869 return; |
| 864 } | 870 } |
| 865 guest_web_contents()->GetController().Reload(false); | 871 guest_web_contents()->GetController().Reload(false); |
| 866 } | 872 } |
| 867 | 873 |
| 874 void WebViewGuest::RenderViewReady() { | |
| 875 guest_web_contents()->SetMainFrameName(name_); | |
| 876 } | |
| 877 | |
| 878 void WebViewGuest::ReportFrameNameChange(const std::string& name) { | |
| 879 name_ = name; | |
| 880 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | |
| 881 args->SetString(webview::kName, name); | |
| 882 DispatchEvent( | |
| 883 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); | |
| 884 } | |
| 885 | |
| 868 void WebViewGuest::LoadHandlerCalled() { | 886 void WebViewGuest::LoadHandlerCalled() { |
| 869 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 887 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 870 DispatchEvent( | 888 DispatchEvent( |
| 871 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); | 889 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); |
| 872 } | 890 } |
| 873 | 891 |
| 874 void WebViewGuest::LoadRedirect(const GURL& old_url, | 892 void WebViewGuest::LoadRedirect(const GURL& old_url, |
| 875 const GURL& new_url, | 893 const GURL& new_url, |
| 876 bool is_top_level) { | 894 bool is_top_level) { |
| 877 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 895 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1198 return; | 1216 return; |
| 1199 | 1217 |
| 1200 // TODO(lazyboy): Implement. | 1218 // TODO(lazyboy): Implement. |
| 1201 DCHECK(!items); | 1219 DCHECK(!items); |
| 1202 | 1220 |
| 1203 ContextMenuDelegate* menu_delegate = | 1221 ContextMenuDelegate* menu_delegate = |
| 1204 ContextMenuDelegate::FromWebContents(guest_web_contents()); | 1222 ContextMenuDelegate::FromWebContents(guest_web_contents()); |
| 1205 menu_delegate->ShowMenu(pending_menu_.Pass()); | 1223 menu_delegate->ShowMenu(pending_menu_.Pass()); |
| 1206 } | 1224 } |
| 1207 | 1225 |
| 1226 void WebViewGuest::SetName(const std::string& name) { | |
| 1227 if (name_ == name) | |
| 1228 return; | |
| 1229 name_ = name; | |
| 1230 guest_web_contents()->SetMainFrameName(name); | |
| 1231 } | |
| 1232 | |
| 1208 void WebViewGuest::Destroy() { | 1233 void WebViewGuest::Destroy() { |
| 1209 if (!attached() && GetOpener()) | 1234 if (!attached() && GetOpener()) |
| 1210 GetOpener()->pending_new_windows_.erase(this); | 1235 GetOpener()->pending_new_windows_.erase(this); |
| 1211 DestroyUnattachedWindows(); | 1236 DestroyUnattachedWindows(); |
| 1212 GuestViewBase::Destroy(); | 1237 GuestViewBase::Destroy(); |
| 1213 } | 1238 } |
| 1214 | 1239 |
| 1215 void WebViewGuest::AddNewContents(content::WebContents* source, | 1240 void WebViewGuest::AddNewContents(content::WebContents* source, |
| 1216 content::WebContents* new_contents, | 1241 content::WebContents* new_contents, |
| 1217 WindowOpenDisposition disposition, | 1242 WindowOpenDisposition disposition, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1256 | 1281 |
| 1257 void WebViewGuest::WebContentsCreated(WebContents* source_contents, | 1282 void WebViewGuest::WebContentsCreated(WebContents* source_contents, |
| 1258 int opener_render_frame_id, | 1283 int opener_render_frame_id, |
| 1259 const base::string16& frame_name, | 1284 const base::string16& frame_name, |
| 1260 const GURL& target_url, | 1285 const GURL& target_url, |
| 1261 content::WebContents* new_contents) { | 1286 content::WebContents* new_contents) { |
| 1262 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); | 1287 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); |
| 1263 CHECK(guest); | 1288 CHECK(guest); |
| 1264 guest->SetOpener(this); | 1289 guest->SetOpener(this); |
| 1265 std::string guest_name = base::UTF16ToUTF8(frame_name); | 1290 std::string guest_name = base::UTF16ToUTF8(frame_name); |
| 1291 guest->name_ = guest_name; | |
| 1266 pending_new_windows_.insert( | 1292 pending_new_windows_.insert( |
| 1267 std::make_pair(guest, NewWindowInfo(target_url, guest_name))); | 1293 std::make_pair(guest, NewWindowInfo(target_url, guest_name))); |
| 1268 } | 1294 } |
| 1269 | 1295 |
| 1296 void WebViewGuest::FrameNameChanged(int render_frame_id, | |
| 1297 bool is_top_level, | |
| 1298 const std::string& name) { | |
| 1299 if (!is_top_level) | |
| 1300 return; | |
| 1301 | |
| 1302 if (name_ == name) | |
| 1303 return; | |
| 1304 | |
| 1305 ReportFrameNameChange(name); | |
| 1306 } | |
| 1307 | |
| 1270 void WebViewGuest::LoadURLWithParams(const GURL& url, | 1308 void WebViewGuest::LoadURLWithParams(const GURL& url, |
| 1271 const content::Referrer& referrer, | 1309 const content::Referrer& referrer, |
| 1272 content::PageTransition transition_type, | 1310 content::PageTransition transition_type, |
| 1273 content::WebContents* web_contents) { | 1311 content::WebContents* web_contents) { |
| 1274 content::NavigationController::LoadURLParams load_url_params(url); | 1312 content::NavigationController::LoadURLParams load_url_params(url); |
| 1275 load_url_params.referrer = referrer; | 1313 load_url_params.referrer = referrer; |
| 1276 load_url_params.transition_type = transition_type; | 1314 load_url_params.transition_type = transition_type; |
| 1277 load_url_params.extra_headers = std::string(); | 1315 load_url_params.extra_headers = std::string(); |
| 1278 if (is_overriding_user_agent_) { | 1316 if (is_overriding_user_agent_) { |
| 1279 load_url_params.override_user_agent = | 1317 load_url_params.override_user_agent = |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1350 bool allow, | 1388 bool allow, |
| 1351 const std::string& user_input) { | 1389 const std::string& user_input) { |
| 1352 WebViewGuest* guest = | 1390 WebViewGuest* guest = |
| 1353 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1391 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1354 if (!guest) | 1392 if (!guest) |
| 1355 return; | 1393 return; |
| 1356 | 1394 |
| 1357 if (!allow) | 1395 if (!allow) |
| 1358 guest->Destroy(); | 1396 guest->Destroy(); |
| 1359 } | 1397 } |
| OLD | NEW |