| 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/guestview.h" | 5 #include "chrome/browser/guestview/guestview.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "chrome/browser/extensions/event_router.h" | 8 #include "chrome/browser/extensions/event_router.h" |
| 9 #include "chrome/browser/guestview/guestview_constants.h" | 9 #include "chrome/browser/guestview/guestview_constants.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 | 37 |
| 38 scoped_ptr<DictionaryValue> GuestView::Event::GetArguments() { | 38 scoped_ptr<DictionaryValue> GuestView::Event::GetArguments() { |
| 39 return args_.Pass(); | 39 return args_.Pass(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 GuestView::GuestView(WebContents* guest_web_contents) | 42 GuestView::GuestView(WebContents* guest_web_contents) |
| 43 : guest_web_contents_(guest_web_contents), | 43 : guest_web_contents_(guest_web_contents), |
| 44 embedder_web_contents_(NULL), | 44 embedder_web_contents_(NULL), |
| 45 embedder_render_process_id_(0), | 45 embedder_render_process_id_(0), |
| 46 embedder_routing_id_(MSG_ROUTING_NONE), | |
| 47 browser_context_(guest_web_contents->GetBrowserContext()), | 46 browser_context_(guest_web_contents->GetBrowserContext()), |
| 48 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()), | 47 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()), |
| 49 view_instance_id_(guestview::kInstanceIDNone) { | 48 view_instance_id_(guestview::kInstanceIDNone) { |
| 50 webcontents_guestview_map.Get().insert( | 49 webcontents_guestview_map.Get().insert( |
| 51 std::make_pair(guest_web_contents, this)); | 50 std::make_pair(guest_web_contents, this)); |
| 52 } | 51 } |
| 53 | 52 |
| 54 // static | 53 // static |
| 55 GuestView* GuestView::FromWebContents(WebContents* web_contents) { | 54 GuestView* GuestView::FromWebContents(WebContents* web_contents) { |
| 56 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); | 55 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); |
| 57 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); | 56 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); |
| 58 return it == guest_map->end() ? NULL : it->second; | 57 return it == guest_map->end() ? NULL : it->second; |
| 59 } | 58 } |
| 60 | 59 |
| 61 // static | 60 // static |
| 62 GuestView* GuestView::From(int embedder_process_id, int guest_instance_id) { | 61 GuestView* GuestView::From(int embedder_process_id, int guest_instance_id) { |
| 63 EmbedderGuestViewMap* guest_map = embedder_guestview_map.Pointer(); | 62 EmbedderGuestViewMap* guest_map = embedder_guestview_map.Pointer(); |
| 64 EmbedderGuestViewMap::iterator it = guest_map->find( | 63 EmbedderGuestViewMap::iterator it = guest_map->find( |
| 65 std::make_pair(embedder_process_id, guest_instance_id)); | 64 std::make_pair(embedder_process_id, guest_instance_id)); |
| 66 return it == guest_map->end() ? NULL : it->second; | 65 return it == guest_map->end() ? NULL : it->second; |
| 67 } | 66 } |
| 68 | 67 |
| 69 void GuestView::Attach(content::WebContents* embedder_web_contents, | 68 void GuestView::Attach(content::WebContents* embedder_web_contents, |
| 70 const std::string& extension_id, | 69 const std::string& extension_id, |
| 71 const base::DictionaryValue& args) { | 70 const base::DictionaryValue& args) { |
| 72 embedder_web_contents_ = embedder_web_contents; | 71 embedder_web_contents_ = embedder_web_contents; |
| 73 embedder_render_process_id_ = | 72 embedder_render_process_id_ = |
| 74 embedder_web_contents->GetRenderProcessHost()->GetID(); | 73 embedder_web_contents->GetRenderProcessHost()->GetID(); |
| 75 embedder_routing_id_ = embedder_web_contents->GetRoutingID(); | |
| 76 extension_id_ = extension_id; | 74 extension_id_ = extension_id; |
| 77 args.GetInteger(guestview::kParameterInstanceId, &view_instance_id_); | 75 args.GetInteger(guestview::kParameterInstanceId, &view_instance_id_); |
| 78 | 76 |
| 79 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_); | 77 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_); |
| 80 embedder_guestview_map.Get().insert(std::make_pair(key, this)); | 78 embedder_guestview_map.Get().insert(std::make_pair(key, this)); |
| 81 | 79 |
| 82 // GuestView::Attach is called prior to initialization (and initial | 80 // GuestView::Attach is called prior to initialization (and initial |
| 83 // navigation) of the guest in the content layer in order to permit mapping | 81 // navigation) of the guest in the content layer in order to permit mapping |
| 84 // the necessary associations between the <*view> element and its guest. This | 82 // the necessary associations between the <*view> element and its guest. This |
| 85 // is needed by the <webview> WebRequest API to allow intercepting resource | 83 // is needed by the <webview> WebRequest API to allow intercepting resource |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 void GuestView::SendQueuedEvents() { | 139 void GuestView::SendQueuedEvents() { |
| 142 if (!attached()) | 140 if (!attached()) |
| 143 return; | 141 return; |
| 144 | 142 |
| 145 while (!pending_events_.empty()) { | 143 while (!pending_events_.empty()) { |
| 146 Event* event = pending_events_.front(); | 144 Event* event = pending_events_.front(); |
| 147 pending_events_.pop(); | 145 pending_events_.pop(); |
| 148 DispatchEvent(event); | 146 DispatchEvent(event); |
| 149 } | 147 } |
| 150 } | 148 } |
| OLD | NEW |