Durable Storage: Refactor browser test and test the basic "deny" flow.
[chromium-blink-merge.git] / extensions / browser / guest_view / guest_view_events.cc
blob843083bc7ba3bc049146273792b35104b0456557
1 // Copyright 2015 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.
5 #include "extensions/browser/guest_view/guest_view_events.h"
7 #include <map>
9 #include "base/lazy_instance.h"
10 #include "components/guest_view/common/guest_view_constants.h"
11 #include "extensions/browser/guest_view/extension_options/extension_options_constants.h"
12 #include "extensions/browser/guest_view/extension_view/extension_view_constants.h"
13 #include "extensions/browser/guest_view/web_view/web_view_constants.h"
14 #include "extensions/common/api/extension_options_internal.h"
16 namespace extensions {
17 namespace guest_view_events {
19 namespace {
21 class EventMap {
22 public:
23 EventMap() {
24 struct NameAndValue {
25 const char* name;
26 events::HistogramValue value;
27 } names_and_values[] = {
28 {webview::kEventContextMenuShow,
29 events::CHROME_WEB_VIEW_INTERNAL_ON_CONTEXT_MENU_SHOW},
30 {api::extension_options_internal::OnClose::kEventName,
31 events::EXTENSION_OPTIONS_INTERNAL_ON_CLOSE},
32 {api::extension_options_internal::OnLoad::kEventName,
33 events::EXTENSION_OPTIONS_INTERNAL_ON_LOAD},
34 {api::extension_options_internal::OnPreferredSizeChanged::kEventName,
35 events::EXTENSION_OPTIONS_INTERNAL_ON_PREFERRED_SIZE_CHANGED},
36 {extensionview::kEventLoadCommit,
37 events::EXTENSION_VIEW_INTERNAL_ON_LOAD_COMMIT},
38 {guest_view::kEventResize, events::GUEST_VIEW_INTERNAL_ON_RESIZE},
39 {webview::kEventBeforeRequest,
40 events::WEB_VIEW_INTERNAL_ON_BEFORE_REQUEST},
41 {webview::kEventBeforeSendHeaders,
42 events::WEB_VIEW_INTERNAL_ON_BEFORE_SEND_HEADERS},
43 {webview::kEventClose, events::WEB_VIEW_INTERNAL_ON_CLOSE},
44 {webview::kEventCompleted, events::WEB_VIEW_INTERNAL_ON_COMPLETED},
45 {webview::kEventConsoleMessage,
46 events::WEB_VIEW_INTERNAL_ON_CONSOLE_MESSAGE},
47 {webview::kEventContentLoad, events::WEB_VIEW_INTERNAL_ON_CONTENT_LOAD},
48 {webview::kEventDialog, events::WEB_VIEW_INTERNAL_ON_DIALOG},
49 {webview::kEventDropLink, events::WEB_VIEW_INTERNAL_ON_DROP_LINK},
50 {webview::kEventExit, events::WEB_VIEW_INTERNAL_ON_EXIT},
51 {webview::kEventExitFullscreen,
52 events::WEB_VIEW_INTERNAL_ON_EXIT_FULLSCREEN},
53 {webview::kEventFindReply, events::WEB_VIEW_INTERNAL_ON_FIND_REPLY},
54 {webview::kEventHeadersReceived,
55 events::WEB_VIEW_INTERNAL_ON_HEADERS_RECEIVED},
56 {webview::kEventFrameNameChanged,
57 events::WEB_VIEW_INTERNAL_ON_FRAME_NAME_CHANGED},
58 {webview::kEventLoadAbort, events::WEB_VIEW_INTERNAL_ON_LOAD_ABORT},
59 {webview::kEventLoadCommit, events::WEB_VIEW_INTERNAL_ON_LOAD_COMMIT},
60 {webview::kEventLoadProgress,
61 events::WEB_VIEW_INTERNAL_ON_LOAD_PROGRESS},
62 {webview::kEventLoadRedirect,
63 events::WEB_VIEW_INTERNAL_ON_LOAD_REDIRECT},
64 {webview::kEventLoadStart, events::WEB_VIEW_INTERNAL_ON_LOAD_START},
65 {webview::kEventLoadStop, events::WEB_VIEW_INTERNAL_ON_LOAD_STOP},
66 {webview::kEventNewWindow, events::WEB_VIEW_INTERNAL_ON_NEW_WINDOW},
67 {webview::kEventPermissionRequest,
68 events::WEB_VIEW_INTERNAL_ON_PERMISSION_REQUEST},
69 {webview::kEventResponseStarted,
70 events::WEB_VIEW_INTERNAL_ON_RESPONSE_STARTED},
71 {webview::kEventResponsive, events::WEB_VIEW_INTERNAL_ON_RESPONSIVE},
72 {webview::kEventSizeChanged, events::WEB_VIEW_INTERNAL_ON_SIZE_CHANGED},
73 {webview::kEventUnresponsive,
74 events::WEB_VIEW_INTERNAL_ON_UNRESPONSIVE},
75 {webview::kEventZoomChange, events::WEB_VIEW_INTERNAL_ON_ZOOM_CHANGE},
77 for (const auto& name_and_value : names_and_values) {
78 values_[name_and_value.name] = name_and_value.value;
82 events::HistogramValue Get(const std::string& event_name) {
83 auto value = values_.find(event_name);
84 return value != values_.end() ? value->second : events::UNKNOWN;
87 private:
88 std::map<std::string, events::HistogramValue> values_;
90 DISALLOW_COPY_AND_ASSIGN(EventMap);
93 base::LazyInstance<EventMap> g_event_map = LAZY_INSTANCE_INITIALIZER;
95 } // namespace
97 events::HistogramValue GetEventHistogramValue(const std::string& event_name) {
98 return g_event_map.Get().Get(event_name);
101 } // namespace guest_view_events
102 } // namespace extensions