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

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

Issue 2078021: First pass at experimental omnibox API. There are plenty of rough edges and (Closed)
Patch Set: no prefer_keyword Created 10 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/extension_omnibox_api.h"
6
7 #include "base/json/json_writer.h"
8 #include "base/string_util.h"
9 #include "base/values.h"
10 #include "chrome/browser/extensions/extension_message_service.h"
11 #include "chrome/browser/profile.h"
12 #include "chrome/common/notification_service.h"
13
14 namespace events {
15 const char kOnInputChanged[] = "experimental.omnibox.onInputChanged/";
16 const char kOnInputEntered[] = "experimental.omnibox.onInputEntered/";
17 }; // namespace events
18
19 // static
20 bool ExtensionOmniboxEventRouter::OnInputChanged(
21 Profile* profile, const std::string& extension_id,
22 const std::string& input, int suggest_id) {
23 std::string event_name = events::kOnInputChanged + extension_id;
24 if (!profile->GetExtensionMessageService()->HasEventListener(event_name))
25 return false;
26
27 ListValue args;
28 args.Set(0, Value::CreateStringValue(input));
29 args.Set(1, Value::CreateIntegerValue(suggest_id));
30 std::string json_args;
31 base::JSONWriter::Write(&args, false, &json_args);
32
33 profile->GetExtensionMessageService()->DispatchEventToRenderers(
34 event_name, json_args, profile->IsOffTheRecord(), GURL());
35 return true;
36 }
37
38 // static
39 void ExtensionOmniboxEventRouter::OnInputEntered(
40 Profile* profile, const std::string& extension_id,
41 const std::string& input) {
42 std::string event_name = events::kOnInputEntered + extension_id;
43
44 ListValue args;
45 args.Set(0, Value::CreateStringValue(input));
46 std::string json_args;
47 base::JSONWriter::Write(&args, false, &json_args);
48
49 profile->GetExtensionMessageService()->DispatchEventToRenderers(
50 event_name, json_args, profile->IsOffTheRecord(), GURL());
51 }
52
53 bool OmniboxSendSuggestionsFunction::RunImpl() {
54 int request_id;
55 ListValue* suggestions_value;
56 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &request_id));
57 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value));
58
59 ExtensionOmniboxSuggestions details(request_id, suggestions_value);
60 NotificationService::current()->Notify(
61 NotificationType::EXTENSION_OMNIBOX_SUGGESTIONS_READY,
62 Source<Profile>(profile_),
63 Details<ExtensionOmniboxSuggestions>(&details));
64
65 return true;
66 }
67
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_omnibox_api.h ('k') | chrome/browser/extensions/extension_omnibox_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698