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

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

Issue 3210007: Add support for a "split" incognito behavior for extensions. (Closed)
Patch Set: latest Created 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extension_omnibox_api.h" 5 #include "chrome/browser/extensions/extension_omnibox_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/extension_message_service.h" 10 #include "chrome/browser/extensions/extension_message_service.h"
(...skipping 18 matching lines...) Expand all
29 const char kSuggestionDescription[] = "description"; 29 const char kSuggestionDescription[] = "description";
30 const char kSuggestionDescriptionStyles[] = "descriptionStyles"; 30 const char kSuggestionDescriptionStyles[] = "descriptionStyles";
31 const char kDescriptionStylesType[] = "type"; 31 const char kDescriptionStylesType[] = "type";
32 const char kDescriptionStylesOffset[] = "offset"; 32 const char kDescriptionStylesOffset[] = "offset";
33 }; // namespace 33 }; // namespace
34 34
35 // static 35 // static
36 void ExtensionOmniboxEventRouter::OnInputStarted( 36 void ExtensionOmniboxEventRouter::OnInputStarted(
37 Profile* profile, const std::string& extension_id) { 37 Profile* profile, const std::string& extension_id) {
38 profile->GetExtensionMessageService()->DispatchEventToExtension( 38 profile->GetExtensionMessageService()->DispatchEventToExtension(
39 extension_id, events::kOnInputStarted, "[]", profile->IsOffTheRecord(), 39 extension_id, events::kOnInputStarted, "[]", profile, GURL());
40 GURL());
41 } 40 }
42 41
43 // static 42 // static
44 bool ExtensionOmniboxEventRouter::OnInputChanged( 43 bool ExtensionOmniboxEventRouter::OnInputChanged(
45 Profile* profile, const std::string& extension_id, 44 Profile* profile, const std::string& extension_id,
46 const std::string& input, int suggest_id) { 45 const std::string& input, int suggest_id) {
47 std::string event_name = ExtensionMessageService::GetPerExtensionEventName( 46 std::string event_name = ExtensionMessageService::GetPerExtensionEventName(
48 events::kOnInputChanged, extension_id); 47 events::kOnInputChanged, extension_id);
49 if (!profile->GetExtensionMessageService()->HasEventListener(event_name)) 48 if (!profile->GetExtensionMessageService()->HasEventListener(event_name))
50 return false; 49 return false;
51 50
52 ListValue args; 51 ListValue args;
53 args.Set(0, Value::CreateStringValue(input)); 52 args.Set(0, Value::CreateStringValue(input));
54 args.Set(1, Value::CreateIntegerValue(suggest_id)); 53 args.Set(1, Value::CreateIntegerValue(suggest_id));
55 std::string json_args; 54 std::string json_args;
56 base::JSONWriter::Write(&args, false, &json_args); 55 base::JSONWriter::Write(&args, false, &json_args);
57 56
58 profile->GetExtensionMessageService()->DispatchEventToExtension( 57 profile->GetExtensionMessageService()->DispatchEventToExtension(
59 extension_id, events::kOnInputChanged, json_args, 58 extension_id, events::kOnInputChanged, json_args, profile, GURL());
60 profile->IsOffTheRecord(), GURL());
61 return true; 59 return true;
62 } 60 }
63 61
64 // static 62 // static
65 void ExtensionOmniboxEventRouter::OnInputEntered( 63 void ExtensionOmniboxEventRouter::OnInputEntered(
66 Profile* profile, const std::string& extension_id, 64 Profile* profile, const std::string& extension_id,
67 const std::string& input) { 65 const std::string& input) {
68 std::string event_name = events::kOnInputEntered + extension_id; 66 std::string event_name = events::kOnInputEntered + extension_id;
69 67
70 ListValue args; 68 ListValue args;
71 args.Set(0, Value::CreateStringValue(input)); 69 args.Set(0, Value::CreateStringValue(input));
72 std::string json_args; 70 std::string json_args;
73 base::JSONWriter::Write(&args, false, &json_args); 71 base::JSONWriter::Write(&args, false, &json_args);
74 72
75 profile->GetExtensionMessageService()->DispatchEventToExtension( 73 profile->GetExtensionMessageService()->DispatchEventToExtension(
76 extension_id, events::kOnInputEntered, json_args, 74 extension_id, events::kOnInputEntered, json_args, profile, GURL());
77 profile->IsOffTheRecord(), GURL());
78 75
79 NotificationService::current()->Notify( 76 NotificationService::current()->Notify(
80 NotificationType::EXTENSION_OMNIBOX_INPUT_ENTERED, 77 NotificationType::EXTENSION_OMNIBOX_INPUT_ENTERED,
81 Source<Profile>(profile), NotificationService::NoDetails()); 78 Source<Profile>(profile), NotificationService::NoDetails());
82 } 79 }
83 80
84 // static 81 // static
85 void ExtensionOmniboxEventRouter::OnInputCancelled( 82 void ExtensionOmniboxEventRouter::OnInputCancelled(
86 Profile* profile, const std::string& extension_id) { 83 Profile* profile, const std::string& extension_id) {
87 profile->GetExtensionMessageService()->DispatchEventToExtension( 84 profile->GetExtensionMessageService()->DispatchEventToExtension(
88 extension_id, events::kOnInputCancelled, "[]", profile->IsOffTheRecord(), 85 extension_id, events::kOnInputCancelled, "[]", profile, GURL());
89 GURL());
90 } 86 }
91 87
92 bool OmniboxSendSuggestionsFunction::RunImpl() { 88 bool OmniboxSendSuggestionsFunction::RunImpl() {
93 ExtensionOmniboxSuggestions suggestions; 89 ExtensionOmniboxSuggestions suggestions;
94 ListValue* suggestions_value; 90 ListValue* suggestions_value;
95 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); 91 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id));
96 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); 92 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value));
97 93
98 suggestions.suggestions.resize(suggestions_value->GetSize()); 94 suggestions.suggestions.resize(suggestions_value->GetSize());
99 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { 95 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 151 }
156 } 152 }
157 153
158 NotificationService::current()->Notify( 154 NotificationService::current()->Notify(
159 NotificationType::EXTENSION_OMNIBOX_SUGGESTIONS_READY, 155 NotificationType::EXTENSION_OMNIBOX_SUGGESTIONS_READY,
160 Source<Profile>(profile_), 156 Source<Profile>(profile_),
161 Details<ExtensionOmniboxSuggestions>(&suggestions)); 157 Details<ExtensionOmniboxSuggestions>(&suggestions));
162 158
163 return true; 159 return true;
164 } 160 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_messages_apitest.cc ('k') | chrome/browser/extensions/extension_popup_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698