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