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

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

Issue 22944002: Implementation of the "Redirect URLs to Packaged Apps" feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review comments + lint errors Created 7 years, 3 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
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/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 12 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
13 #include "chrome/browser/extensions/event_router.h" 13 #include "chrome/browser/extensions/event_router.h"
14 #include "chrome/browser/extensions/extension_system.h" 14 #include "chrome/browser/extensions/extension_system.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/extensions/api/app_runtime.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
19 20
20 namespace extensions { 21 namespace extensions {
21 22
22 namespace { 23 namespace {
23 24
24 const char kOnLaunchedEvent[] = "app.runtime.onLaunched"; 25 const char kOnLaunchedEvent[] = "app.runtime.onLaunched";
25 const char kOnRestartedEvent[] = "app.runtime.onRestarted"; 26 const char kOnRestartedEvent[] = "app.runtime.onRestarted";
(...skipping 15 matching lines...) Expand all
41 system->event_router()->DispatchEventToExtension(extension_id, event.Pass()); 42 system->event_router()->DispatchEventToExtension(extension_id, event.Pass());
42 system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent, 43 system->event_router()->RemoveLazyEventListener(kOnLaunchedEvent,
43 extension_id); 44 extension_id);
44 } 45 }
45 46
46 } // anonymous namespace 47 } // anonymous namespace
47 48
48 // static. 49 // static.
49 void AppEventRouter::DispatchOnLaunchedEvent( 50 void AppEventRouter::DispatchOnLaunchedEvent(
50 Profile* profile, const Extension* extension) { 51 Profile* profile, const Extension* extension) {
51 scoped_ptr<ListValue> arguments(new ListValue()); 52 scoped_ptr<ListValue> args(new ListValue());
52 DispatchOnLaunchedEventImpl(extension->id(), arguments.Pass(), profile); 53 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile);
53 } 54 }
54 55
55 DictionaryValue* DictionaryFromSavedFileEntry( 56 DictionaryValue* DictionaryFromSavedFileEntry(
56 const app_file_handler_util::GrantedFileEntry& file_entry) { 57 const app_file_handler_util::GrantedFileEntry& file_entry) {
57 DictionaryValue* result = new DictionaryValue(); 58 DictionaryValue* result = new DictionaryValue();
58 result->SetString("id", file_entry.id); 59 result->SetString("id", file_entry.id);
59 result->SetString("fileSystemId", file_entry.filesystem_id); 60 result->SetString("fileSystemId", file_entry.filesystem_id);
60 result->SetString("baseName", file_entry.registered_name); 61 result->SetString("baseName", file_entry.registered_name);
61 return result; 62 return result;
62 } 63 }
(...skipping 12 matching lines...) Expand all
75 scoped_ptr<ListValue> arguments(new ListValue()); 76 scoped_ptr<ListValue> arguments(new ListValue());
76 arguments->Append(file_entries_list); 77 arguments->Append(file_entries_list);
77 scoped_ptr<Event> event(new Event(kOnRestartedEvent, arguments.Pass())); 78 scoped_ptr<Event> event(new Event(kOnRestartedEvent, arguments.Pass()));
78 event->restrict_to_profile = profile; 79 event->restrict_to_profile = profile;
79 extensions::ExtensionSystem::Get(profile)->event_router()-> 80 extensions::ExtensionSystem::Get(profile)->event_router()->
80 DispatchEventToExtension(extension->id(), event.Pass()); 81 DispatchEventToExtension(extension->id(), event.Pass());
81 } 82 }
82 83
83 // static. 84 // static.
84 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry( 85 void AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
85 Profile* profile, const Extension* extension, 86 Profile* profile,
86 const std::string& handler_id, const std::string& mime_type, 87 const Extension* extension,
87 const std::string& file_system_id, const std::string& base_name) { 88 const std::string& handler_id,
89 const std::string& mime_type,
90 const std::string& file_system_id,
91 const std::string& base_name) {
88 scoped_ptr<ListValue> args(new ListValue()); 92 scoped_ptr<ListValue> args(new ListValue());
89 DictionaryValue* launch_data = new DictionaryValue(); 93 DictionaryValue* launch_data = new DictionaryValue();
90 launch_data->SetString("id", handler_id); 94 launch_data->SetString("id", handler_id);
91 DictionaryValue* launch_item = new DictionaryValue; 95 DictionaryValue* launch_item = new DictionaryValue;
92 launch_item->SetString("fileSystemId", file_system_id); 96 launch_item->SetString("fileSystemId", file_system_id);
93 launch_item->SetString("baseName", base_name); 97 launch_item->SetString("baseName", base_name);
94 launch_item->SetString("mimeType", mime_type); 98 launch_item->SetString("mimeType", mime_type);
95 ListValue* items = new ListValue; 99 ListValue* items = new ListValue;
96 items->Append(launch_item); 100 items->Append(launch_item);
97 launch_data->Set("items", items); 101 launch_data->Set("items", items);
98 args->Append(launch_data); 102 args->Append(launch_data);
99 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile); 103 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile);
100 } 104 }
101 105
106 // static.
107 void AppEventRouter::DispatchOnLaunchedEventWithUrl(
108 Profile* profile,
109 const Extension* extension,
110 const std::string& handler_id,
111 const GURL& url,
112 const GURL& referrer_url) {
113 // TODO (sergeygs): Use the same way of creating an event (using the generated
benwells 2013/08/30 05:41:39 Nit: Move this TODO to the code above where it is
sergeygs 2013/09/02 07:36:22 Done.
114 // boilerplate) in methods above.
115 api::app_runtime::LaunchData launch_data;
116 launch_data.id.reset(new std::string(handler_id));
117 launch_data.url.reset(new std::string(url.spec()));
118 launch_data.referrer_url.reset(new std::string(referrer_url.spec()));
119 scoped_ptr<ListValue> args(new ListValue());
120 args->Append(launch_data.ToValue().release());
121 DispatchOnLaunchedEventImpl(extension->id(), args.Pass(), profile);
122 }
123
102 } // namespace extensions 124 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698