| 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/webview/webview_guest.h" | 5 #include "chrome/browser/webview/webview_guest.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 8 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 9 #include "chrome/browser/extensions/api/webview/webview_api_constants.h" | 9 #include "chrome/browser/extensions/api/webview/webview_api_constants.h" |
| 10 #include "chrome/browser/extensions/event_router.h" | 10 #include "chrome/browser/extensions/event_router.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 // static | 63 // static |
| 64 WebViewGuest* WebViewGuest::From(int embedder_process_id, | 64 WebViewGuest* WebViewGuest::From(int embedder_process_id, |
| 65 int guest_instance_id) { | 65 int guest_instance_id) { |
| 66 WebViewGuestMap* guest_map = webview_guest_map.Pointer(); | 66 WebViewGuestMap* guest_map = webview_guest_map.Pointer(); |
| 67 WebViewGuestMap::iterator it = guest_map->find( | 67 WebViewGuestMap::iterator it = guest_map->find( |
| 68 std::make_pair(embedder_process_id, guest_instance_id)); | 68 std::make_pair(embedder_process_id, guest_instance_id)); |
| 69 return it == guest_map->end() ? NULL : it->second; | 69 return it == guest_map->end() ? NULL : it->second; |
| 70 } | 70 } |
| 71 | 71 |
| 72 void WebViewGuest::Go(int relative_index) { |
| 73 web_contents()->GetController().GoToOffset(relative_index); |
| 74 } |
| 75 |
| 72 WebViewGuest::~WebViewGuest() { | 76 WebViewGuest::~WebViewGuest() { |
| 73 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_); |
| 74 webview_guest_map.Get().erase(key); | 78 webview_guest_map.Get().erase(key); |
| 75 } | 79 } |
| 76 | 80 |
| 77 void WebViewGuest::DispatchEvent(const std::string& event_name, | 81 void WebViewGuest::DispatchEvent(const std::string& event_name, |
| 78 scoped_ptr<DictionaryValue> event) { | 82 scoped_ptr<DictionaryValue> event) { |
| 79 Profile* profile = Profile::FromBrowserContext( | 83 Profile* profile = Profile::FromBrowserContext( |
| 80 web_contents()->GetBrowserContext()); | 84 web_contents()->GetBrowserContext()); |
| 81 | 85 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 | 97 |
| 94 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 98 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 95 int64 frame_id, | 99 int64 frame_id, |
| 96 bool is_main_frame, | 100 bool is_main_frame, |
| 97 const GURL& url, | 101 const GURL& url, |
| 98 content::PageTransition transition_type, | 102 content::PageTransition transition_type, |
| 99 content::RenderViewHost* render_view_host) { | 103 content::RenderViewHost* render_view_host) { |
| 100 scoped_ptr<DictionaryValue> event(new DictionaryValue()); | 104 scoped_ptr<DictionaryValue> event(new DictionaryValue()); |
| 101 event->SetString(keys::kUrl, url.spec()); | 105 event->SetString(keys::kUrl, url.spec()); |
| 102 event->SetBoolean(keys::kIsTopLevel, is_main_frame); | 106 event->SetBoolean(keys::kIsTopLevel, is_main_frame); |
| 107 event->SetInteger(keys::kCurrentEntryIndex, |
| 108 web_contents()->GetController().GetCurrentEntryIndex()); |
| 109 event->SetInteger(keys::kEntryCount, |
| 110 web_contents()->GetController().GetEntryCount()); |
| 103 DispatchEvent(keys::kEventLoadCommit, event.Pass()); | 111 DispatchEvent(keys::kEventLoadCommit, event.Pass()); |
| 104 } | 112 } |
| 105 | 113 |
| 106 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { | 114 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { |
| 107 RemoveWebViewFromExtensionRendererState(web_contents); | 115 RemoveWebViewFromExtensionRendererState(web_contents); |
| 108 content::BrowserThread::PostTask( | 116 content::BrowserThread::PostTask( |
| 109 content::BrowserThread::IO, | 117 content::BrowserThread::IO, |
| 110 FROM_HERE, | 118 FROM_HERE, |
| 111 base::Bind( | 119 base::Bind( |
| 112 &RemoveWebViewEventListenersOnIOThread, | 120 &RemoveWebViewEventListenersOnIOThread, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 140 content::BrowserThread::PostTask( | 148 content::BrowserThread::PostTask( |
| 141 content::BrowserThread::IO, FROM_HERE, | 149 content::BrowserThread::IO, FROM_HERE, |
| 142 base::Bind( | 150 base::Bind( |
| 143 &ExtensionRendererState::RemoveWebView, | 151 &ExtensionRendererState::RemoveWebView, |
| 144 base::Unretained(ExtensionRendererState::GetInstance()), | 152 base::Unretained(ExtensionRendererState::GetInstance()), |
| 145 web_contents->GetRenderProcessHost()->GetID(), | 153 web_contents->GetRenderProcessHost()->GetID(), |
| 146 web_contents->GetRoutingID())); | 154 web_contents->GetRoutingID())); |
| 147 } | 155 } |
| 148 | 156 |
| 149 } // namespace chrome | 157 } // namespace chrome |
| OLD | NEW |