Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/browser/adview/adview_guest.cc

Issue 17165004: <webview>: Partially migrate loadcommit event from content to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with ToT Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/adview/adview_guest.h ('k') | chrome/browser/chrome_content_browser_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/adview/adview_guest.h"
6
7 #include "base/lazy_instance.h"
8 #include "chrome/browser/adview/adview_constants.h"
9 #include "chrome/browser/extensions/event_router.h"
10 #include "chrome/browser/extensions/extension_system.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/site_instance.h"
15 #include "content/public/browser/web_contents.h"
16
17 using content::WebContents;
18
19 namespace {
20
21 typedef std::map<std::pair<int, int>, AdViewGuest*> AdViewGuestMap;
22 base::LazyInstance<AdViewGuestMap> adview_guest_map =
23 LAZY_INSTANCE_INITIALIZER;
24
25 } // namespace
26
27 AdViewGuest::AdViewGuest(WebContents* guest_web_contents,
28 WebContents* embedder_web_contents,
29 const std::string& extension_id,
30 int view_instance_id,
31 const base::DictionaryValue& args)
32 : WebContentsObserver(guest_web_contents),
33 embedder_web_contents_(embedder_web_contents),
34 extension_id_(extension_id),
35 embedder_render_process_id_(
36 embedder_web_contents->GetRenderProcessHost()->GetID()),
37 profile_(guest_web_contents->GetBrowserContext()),
38 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()),
39 view_instance_id_(view_instance_id) {
40 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_);
41 adview_guest_map.Get().insert(std::make_pair(key, this));
42 }
43
44 // static
45 AdViewGuest* AdViewGuest::From(int embedder_process_id,
46 int guest_instance_id) {
47 AdViewGuestMap* guest_map = adview_guest_map.Pointer();
48 AdViewGuestMap::iterator it = guest_map->find(
49 std::make_pair(embedder_process_id, guest_instance_id));
50 return it == guest_map->end() ? NULL : it->second;
51 }
52
53 AdViewGuest::~AdViewGuest() {
54 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_);
55 adview_guest_map.Get().erase(key);
56 }
57
58 void AdViewGuest::DispatchEvent(const std::string& event_name,
59 scoped_ptr<DictionaryValue> event) {
60 Profile* profile = Profile::FromBrowserContext(
61 web_contents()->GetBrowserContext());
62
63 extensions::EventFilteringInfo info;
64 info.SetURL(GURL());
65 info.SetInstanceID(guest_instance_id_);
66 scoped_ptr<ListValue> args(new ListValue());
67 args->Append(event.release());
68
69 extensions::EventRouter::DispatchEvent(
70 embedder_web_contents_, profile, extension_id_,
71 event_name, args.Pass(),
72 extensions::EventRouter::USER_GESTURE_UNKNOWN, info);
73 }
74
75 void AdViewGuest::DidCommitProvisionalLoadForFrame(
76 int64 frame_id,
77 bool is_main_frame,
78 const GURL& url,
79 content::PageTransition transition_type,
80 content::RenderViewHost* render_view_host) {
81 scoped_ptr<DictionaryValue> event(new DictionaryValue());
82 event->SetString(adview::kUrl, url.spec());
83 event->SetBoolean(adview::kIsTopLevel, is_main_frame);
84 DispatchEvent(adview::kEventLoadCommit, event.Pass());
85 }
86
87 void AdViewGuest::WebContentsDestroyed(WebContents* web_contents) {
88 delete this;
89 }
OLDNEW
« no previous file with comments | « chrome/browser/adview/adview_guest.h ('k') | chrome/browser/chrome_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698