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

Side by Side Diff: chrome/browser/extensions/api/app_runtime/app_runtime_api.cc

Issue 11348301: Force-load a lazy background page whenever an extension is enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
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/api/app_runtime/app_runtime_api.h" 5 #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 19 matching lines...) Expand all
30 const char kCallbackNotFoundError[] = 30 const char kCallbackNotFoundError[] =
31 "WebIntent callback not found; perhaps already responded to"; 31 "WebIntent callback not found; perhaps already responded to";
32 32
33 } // anonymous namespace 33 } // anonymous namespace
34 34
35 namespace extensions { 35 namespace extensions {
36 36
37 // static. 37 // static.
38 void AppEventRouter::DispatchOnLaunchedEvent( 38 void AppEventRouter::DispatchOnLaunchedEvent(
39 Profile* profile, const Extension* extension) { 39 Profile* profile, const Extension* extension) {
40 ExtensionSystem* system = ExtensionSystem::Get(profile);
40 scoped_ptr<ListValue> arguments(new ListValue()); 41 scoped_ptr<ListValue> arguments(new ListValue());
41 extensions::ExtensionSystem::Get(profile)->event_router()-> 42 system->event_router()->AddLazyEventListener(kOnLaunchedEvent,
42 DispatchEventToExtension(extension->id(), kOnLaunchedEvent, 43 extension->id());
43 arguments.Pass(), profile, GURL()); 44 system->event_router()->DispatchEventToExtension(
45 extension->id(), kOnLaunchedEvent, arguments.Pass(), profile, GURL());
46 system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent,
47 extension->id());
Matt Perry 2012/11/29 20:24:46 If you go this route, can you move this chunk to a
Marijn Kruisselbrink 2012/11/29 21:07:19 Done.
44 } 48 }
45 49
46 // static. 50 // static.
47 void AppEventRouter::DispatchOnRestartedEvent( 51 void AppEventRouter::DispatchOnRestartedEvent(
48 Profile* profile, const Extension* extension) { 52 Profile* profile, const Extension* extension) {
49 scoped_ptr<ListValue> arguments(new ListValue()); 53 scoped_ptr<ListValue> arguments(new ListValue());
50 extensions::ExtensionSystem::Get(profile)->event_router()-> 54 extensions::ExtensionSystem::Get(profile)->event_router()->
51 DispatchEventToExtension(extension->id(), kOnRestartedEvent, 55 DispatchEventToExtension(extension->id(), kOnRestartedEvent,
52 arguments.Pass(), profile, GURL()); 56 arguments.Pass(), profile, GURL());
53 } 57 }
54 58
55 // static. 59 // static.
56 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( 60 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
57 Profile* profile, const Extension* extension, const string16& action, 61 Profile* profile, const Extension* extension, const string16& action,
58 const std::string& handler_id, const std::string& mime_type, 62 const std::string& handler_id, const std::string& mime_type,
59 const std::string& file_system_id, const std::string& base_name) { 63 const std::string& file_system_id, const std::string& base_name) {
60 scoped_ptr<ListValue> args(new ListValue()); 64 scoped_ptr<ListValue> args(new ListValue());
61 DictionaryValue* launch_data = new DictionaryValue(); 65 DictionaryValue* launch_data = new DictionaryValue();
62 launch_data->SetString("id", handler_id); 66 launch_data->SetString("id", handler_id);
63 DictionaryValue* launch_item = new DictionaryValue; 67 DictionaryValue* launch_item = new DictionaryValue;
64 launch_item->SetString("fileSystemId", file_system_id); 68 launch_item->SetString("fileSystemId", file_system_id);
65 launch_item->SetString("baseName", base_name); 69 launch_item->SetString("baseName", base_name);
66 launch_item->SetString("mimeType", mime_type); 70 launch_item->SetString("mimeType", mime_type);
67 ListValue* items = new ListValue; 71 ListValue* items = new ListValue;
68 items->Append(launch_item); 72 items->Append(launch_item);
69 launch_data->Set("items", items); 73 launch_data->Set("items", items);
70 args->Append(launch_data); 74 args->Append(launch_data);
71 extensions::ExtensionSystem::Get(profile)->event_router()-> 75 ExtensionSystem* system = ExtensionSystem::Get(profile);
72 DispatchEventToExtension(extension->id(), kOnLaunchedEvent, args.Pass(), 76 system->event_router()->AddLazyEventListener(kOnLaunchedEvent,
73 profile, GURL()); 77 extension->id());
78 system->event_router()->DispatchEventToExtension(
79 extension->id(), kOnLaunchedEvent, args.Pass(), profile, GURL());
80 system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent,
81 extension->id());
74 } 82 }
75 83
76 // static. 84 // static.
77 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent( 85 void AppEventRouter::DispatchOnLaunchedEventWithWebIntent(
78 Profile* profile, const Extension* extension, 86 Profile* profile, const Extension* extension,
79 content::WebIntentsDispatcher* intents_dispatcher, 87 content::WebIntentsDispatcher* intents_dispatcher,
80 content::WebContents* source) { 88 content::WebContents* source) {
81 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent(); 89 webkit_glue::WebIntentData web_intent_data = intents_dispatcher->GetIntent();
82 scoped_ptr<ListValue> args(new ListValue()); 90 scoped_ptr<ListValue> args(new ListValue());
83 DictionaryValue* launch_data = new DictionaryValue(); 91 DictionaryValue* launch_data = new DictionaryValue();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 break; 127 break;
120 default: 128 default:
121 NOTREACHED(); 129 NOTREACHED();
122 break; 130 break;
123 } 131 }
124 DCHECK(args->GetSize() == 2); // intent_id must be our third argument. 132 DCHECK(args->GetSize() == 2); // intent_id must be our third argument.
125 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile); 133 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile);
126 int intent_id = 134 int intent_id =
127 callbacks->RegisterCallback(extension, intents_dispatcher, source); 135 callbacks->RegisterCallback(extension, intents_dispatcher, source);
128 args->Append(base::Value::CreateIntegerValue(intent_id)); 136 args->Append(base::Value::CreateIntegerValue(intent_id));
129 extensions::ExtensionSystem::Get(profile)->event_router()-> 137 ExtensionSystem* system = ExtensionSystem::Get(profile);
130 DispatchEventToExtension(extension->id(), kOnLaunchedEvent, args.Pass(), 138 system->event_router()->AddLazyEventListener(kOnLaunchedEvent,
131 profile, GURL()); 139 extension->id());
140 system->event_router()->DispatchEventToExtension(
141 extension->id(), kOnLaunchedEvent, args.Pass(), profile, GURL());
142 system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent,
143 extension->id());
132 } 144 }
133 145
134 bool AppRuntimePostIntentResponseFunction::RunImpl() { 146 bool AppRuntimePostIntentResponseFunction::RunImpl() {
135 DictionaryValue* details = NULL; 147 DictionaryValue* details = NULL;
136 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 148 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
137 149
138 int intent_id = 0; 150 int intent_id = 0;
139 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id)); 151 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kIntentIdKey, &intent_id));
140 152
141 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile()); 153 WebIntentCallbacks* callbacks = WebIntentCallbacks::Get(profile());
(...skipping 12 matching lines...) Expand all
154 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS; 166 reply_type = webkit_glue::WEB_INTENT_REPLY_SUCCESS;
155 167
156 std::string data; 168 std::string data;
157 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data)); 169 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIntentDataKey, &data));
158 170
159 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data)); 171 intents_dispatcher->SendReplyMessage(reply_type, UTF8ToUTF16(data));
160 return true; 172 return true;
161 } 173 }
162 174
163 } // namespace extensions 175 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service.cc » ('j') | chrome/browser/extensions/extension_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698