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

Side by Side Diff: chrome/browser/ui/ash/cast_config_delegate_chromeos.cc

Issue 2424183002: Remove Chromecast extension support from cast system tray menu. (Closed)
Patch Set: Initial patch Created 4 years, 1 month 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 2015 The Chromium Authors. All rights reserved.
achuithb 2016/10/27 19:38:59 RIP :'(
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/ui/ash/cast_config_delegate_chromeos.h"
6
7 #include <stddef.h>
8
9 #include <memory>
10 #include <string>
11 #include <utility>
12
13 #include "base/macros.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/extensions/api/cast_devices_private/cast_devices_privat e_api.h"
16 #include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h"
17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/browser_navigator.h"
19 #include "chrome/browser/ui/browser_navigator_params.h"
20 #include "chrome/common/extensions/api/cast_devices_private.h"
21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/render_view_host.h"
24 #include "extensions/browser/event_router.h"
25 #include "extensions/browser/extension_host.h"
26 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/process_manager.h"
28 #include "extensions/common/extension.h"
29
30 namespace chromeos {
31 namespace {
32
33 Profile* GetProfile() {
34 // TODO(jdufault): Figure out how to correctly handle multiprofile mode.
35 // See crbug.com/488751
36 return ProfileManager::GetActiveUserProfile();
37 }
38
39 // Returns the cast extension if it exists.
40 const extensions::Extension* FindCastExtension() {
41 Profile* profile = GetProfile();
42 const extensions::ExtensionRegistry* extension_registry =
43 extensions::ExtensionRegistry::Get(profile);
44 const extensions::ExtensionSet& enabled_extensions =
45 extension_registry->enabled_extensions();
46
47 for (size_t i = 0; i < arraysize(extensions::kChromecastExtensionIds); ++i) {
48 const std::string extension_id(extensions::kChromecastExtensionIds[i]);
49 if (enabled_extensions.Contains(extension_id)) {
50 return extension_registry->GetExtensionById(
51 extension_id, extensions::ExtensionRegistry::ENABLED);
52 }
53 }
54 return nullptr;
55 }
56
57 } // namespace
58
59 CastConfigDelegateChromeos::CastConfigDelegateChromeos() {
60 }
61
62 CastConfigDelegateChromeos::~CastConfigDelegateChromeos() {
63 }
64
65 bool CastConfigDelegateChromeos::HasCastExtension() const {
66 return FindCastExtension() != nullptr;
67 }
68
69 void CastConfigDelegateChromeos::RequestDeviceRefresh() {
70 std::unique_ptr<base::ListValue> args =
71 extensions::api::cast_devices_private::UpdateDevicesRequested::Create();
72 std::unique_ptr<extensions::Event> event(new extensions::Event(
73 extensions::events::CAST_DEVICES_PRIVATE_ON_UPDATE_DEVICES_REQUESTED,
74 extensions::api::cast_devices_private::UpdateDevicesRequested::kEventName,
75 std::move(args)));
76 extensions::EventRouter::Get(GetProfile())
77 ->DispatchEventToExtension(FindCastExtension()->id(), std::move(event));
78 }
79
80 void CastConfigDelegateChromeos::CastToReceiver(
81 const std::string& receiver_id) {
82 std::unique_ptr<base::ListValue> args =
83 extensions::api::cast_devices_private::StartCast::Create(receiver_id);
84 std::unique_ptr<extensions::Event> event(new extensions::Event(
85 extensions::events::CAST_DEVICES_PRIVATE_ON_START_CAST,
86 extensions::api::cast_devices_private::StartCast::kEventName,
87 std::move(args)));
88 extensions::EventRouter::Get(GetProfile())
89 ->DispatchEventToExtension(FindCastExtension()->id(), std::move(event));
90 }
91
92 void CastConfigDelegateChromeos::StopCasting(const std::string& activity_id) {
93 std::unique_ptr<base::ListValue> args =
94 extensions::api::cast_devices_private::StopCast::Create("user-stop");
95 std::unique_ptr<extensions::Event> event(new extensions::Event(
96 extensions::events::CAST_DEVICES_PRIVATE_ON_STOP_CAST,
97 extensions::api::cast_devices_private::StopCast::kEventName,
98 std::move(args)));
99 extensions::EventRouter::Get(GetProfile())
100 ->DispatchEventToExtension(FindCastExtension()->id(), std::move(event));
101 }
102
103 bool CastConfigDelegateChromeos::HasOptions() const {
104 return true;
105 }
106
107 void CastConfigDelegateChromeos::LaunchCastOptions() {
108 chrome::NavigateParams params(
109 ProfileManager::GetActiveUserProfile(),
110 FindCastExtension()->GetResourceURL("options.html"),
111 ui::PAGE_TRANSITION_LINK);
112 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
113 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
114 chrome::Navigate(&params);
115 }
116
117 void CastConfigDelegateChromeos::AddObserver(
118 ash::CastConfigDelegate::Observer* observer) {
119 return extensions::CastDeviceUpdateListeners::Get(GetProfile())
120 ->AddObserver(observer);
121 }
122
123 void CastConfigDelegateChromeos::RemoveObserver(
124 ash::CastConfigDelegate::Observer* observer) {
125 return extensions::CastDeviceUpdateListeners::Get(GetProfile())
126 ->RemoveObserver(observer);
127 }
128
129 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698