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

Side by Side Diff: chrome/browser/extensions/event_router.cc

Issue 15825008: Remove the event URL security check out of the renderer and into the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add self check 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/event_router.h ('k') | chrome/common/extensions/extension_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/event_router.h" 5 #include "chrome/browser/extensions/event_router.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 // static 136 // static
137 void EventRouter::DispatchExtensionMessage(IPC::Sender* ipc_sender, 137 void EventRouter::DispatchExtensionMessage(IPC::Sender* ipc_sender,
138 void* profile_id, 138 void* profile_id,
139 const std::string& extension_id, 139 const std::string& extension_id,
140 const std::string& event_name, 140 const std::string& event_name,
141 ListValue* event_args, 141 ListValue* event_args,
142 const GURL& event_url,
143 UserGestureState user_gesture, 142 UserGestureState user_gesture,
144 const EventFilteringInfo& info) { 143 const EventFilteringInfo& info) {
145 if (ActivityLog::IsLogEnabled()) { 144 if (ActivityLog::IsLogEnabled()) {
146 LogExtensionEventMessage(profile_id, extension_id, event_name, 145 LogExtensionEventMessage(profile_id, extension_id, event_name,
147 scoped_ptr<ListValue>(event_args->DeepCopy())); 146 scoped_ptr<ListValue>(event_args->DeepCopy()));
148 } 147 }
149 148
150 ListValue args; 149 ListValue args;
151 args.Set(0, Value::CreateStringValue(event_name)); 150 args.Set(0, Value::CreateStringValue(event_name));
152 args.Set(1, event_args); 151 args.Set(1, event_args);
153 args.Set(2, info.AsValue().release()); 152 args.Set(2, info.AsValue().release());
154 ipc_sender->Send(new ExtensionMsg_MessageInvoke(MSG_ROUTING_CONTROL, 153 ipc_sender->Send(new ExtensionMsg_MessageInvoke(
155 extension_id, kDispatchEvent, args, event_url, 154 MSG_ROUTING_CONTROL,
155 extension_id,
156 kDispatchEvent,
157 args,
156 user_gesture == USER_GESTURE_ENABLED)); 158 user_gesture == USER_GESTURE_ENABLED));
157 159
158 // DispatchExtensionMessage does _not_ take ownership of event_args, so we 160 // DispatchExtensionMessage does _not_ take ownership of event_args, so we
159 // must ensure that the destruction of args does not attempt to free it. 161 // must ensure that the destruction of args does not attempt to free it.
160 Value* removed_event_args = NULL; 162 Value* removed_event_args = NULL;
161 args.Remove(1, &removed_event_args); 163 args.Remove(1, &removed_event_args);
162 } 164 }
163 165
164 // static 166 // static
165 void EventRouter::DispatchEvent(IPC::Sender* ipc_sender, 167 void EventRouter::DispatchEvent(IPC::Sender* ipc_sender,
166 void* profile_id, 168 void* profile_id,
167 const std::string& extension_id, 169 const std::string& extension_id,
168 const std::string& event_name, 170 const std::string& event_name,
169 scoped_ptr<ListValue> event_args, 171 scoped_ptr<ListValue> event_args,
170 const GURL& event_url,
171 UserGestureState user_gesture, 172 UserGestureState user_gesture,
172 const EventFilteringInfo& info) { 173 const EventFilteringInfo& info) {
173 DispatchExtensionMessage(ipc_sender, profile_id, extension_id, event_name, 174 DispatchExtensionMessage(ipc_sender, profile_id, extension_id, event_name,
174 event_args.get(), event_url, user_gesture, info); 175 event_args.get(), user_gesture, info);
175 176
176 BrowserThread::PostTask( 177 BrowserThread::PostTask(
177 BrowserThread::UI, 178 BrowserThread::UI,
178 FROM_HERE, 179 FROM_HERE,
179 base::Bind(&EventRouter::IncrementInFlightEventsOnUI, 180 base::Bind(&EventRouter::IncrementInFlightEventsOnUI,
180 profile_id, 181 profile_id,
181 extension_id)); 182 extension_id));
182 } 183 }
183 184
184 EventRouter::EventRouter(Profile* profile, ExtensionPrefs* extension_prefs) 185 EventRouter::EventRouter(Profile* profile, ExtensionPrefs* extension_prefs)
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 process->GetBrowserContext()); 599 process->GetBrowserContext());
599 ProcessMap* process_map = ExtensionSystem::Get(listener_profile)-> 600 ProcessMap* process_map = ExtensionSystem::Get(listener_profile)->
600 extension_service()->process_map(); 601 extension_service()->process_map();
601 // If the event is privileged, only send to extension processes. Otherwise, 602 // If the event is privileged, only send to extension processes. Otherwise,
602 // it's OK to send to normal renderers (e.g., for content scripts). 603 // it's OK to send to normal renderers (e.g., for content scripts).
603 if (ExtensionAPI::GetSharedInstance()->IsPrivileged(event->event_name) && 604 if (ExtensionAPI::GetSharedInstance()->IsPrivileged(event->event_name) &&
604 !process_map->Contains(extension->id(), process->GetID())) { 605 !process_map->Contains(extension->id(), process->GetID())) {
605 return; 606 return;
606 } 607 }
607 608
609 // If the event is restricted to a URL, only dispatch if the extension has
610 // permission for it (or if the event originated from itself).
611 if (!event->event_url.is_empty() &&
612 event->event_url.host() != extension->id() &&
613 !extension->GetActivePermissions()->HasEffectiveAccessToURL(
614 event->event_url)) {
615 return;
616 }
617
608 if (!CanDispatchEventToProfile(listener_profile, extension, event)) 618 if (!CanDispatchEventToProfile(listener_profile, extension, event))
609 return; 619 return;
610 620
611 if (!event->will_dispatch_callback.is_null()) { 621 if (!event->will_dispatch_callback.is_null()) {
612 event->will_dispatch_callback.Run(listener_profile, extension, 622 event->will_dispatch_callback.Run(listener_profile, extension,
613 event->event_args.get()); 623 event->event_args.get());
614 } 624 }
615 625
616 DispatchExtensionMessage(process, listener_profile, extension_id, 626 DispatchExtensionMessage(process, listener_profile, extension->id(),
617 event->event_name, event->event_args.get(), 627 event->event_name, event->event_args.get(),
618 event->event_url, event->user_gesture, 628 event->user_gesture, event->filter_info);
619 event->filter_info);
620 IncrementInFlightEvents(listener_profile, extension); 629 IncrementInFlightEvents(listener_profile, extension);
621 } 630 }
622 631
623 bool EventRouter::CanDispatchEventToProfile(Profile* profile, 632 bool EventRouter::CanDispatchEventToProfile(Profile* profile,
624 const Extension* extension, 633 const Extension* extension,
625 const linked_ptr<Event>& event) { 634 const linked_ptr<Event>& event) {
626 // Is this event from a different profile than the renderer (ie, an 635 // Is this event from a different profile than the renderer (ie, an
627 // incognito tab event sent to a normal process, or vice versa). 636 // incognito tab event sent to a normal process, or vice versa).
628 bool cross_incognito = 637 bool cross_incognito =
629 event->restrict_to_profile && profile != event->restrict_to_profile; 638 event->restrict_to_profile && profile != event->restrict_to_profile;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 copy->will_dispatch_callback = will_dispatch_callback; 863 copy->will_dispatch_callback = will_dispatch_callback;
855 return copy; 864 return copy;
856 } 865 }
857 866
858 EventListenerInfo::EventListenerInfo(const std::string& event_name, 867 EventListenerInfo::EventListenerInfo(const std::string& event_name,
859 const std::string& extension_id) 868 const std::string& extension_id)
860 : event_name(event_name), 869 : event_name(event_name),
861 extension_id(extension_id) {} 870 extension_id(extension_id) {}
862 871
863 } // namespace extensions 872 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/event_router.h ('k') | chrome/common/extensions/extension_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698