| Index: components/arc/intent_helper/open_with_menu_observer.h
|
| diff --git a/components/arc/intent_helper/open_with_menu_observer.h b/components/arc/intent_helper/open_with_menu_observer.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4c9d785e3521b0a1768f1031173697bdd391bb05
|
| --- /dev/null
|
| +++ b/components/arc/intent_helper/open_with_menu_observer.h
|
| @@ -0,0 +1,101 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef COMPONENTS_ARC_INTENT_HELPER_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_
|
| +#define COMPONENTS_ARC_INTENT_HELPER_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_
|
| +
|
| +#include <set>
|
| +#include <unordered_map>
|
| +#include <utility>
|
| +
|
| +#include "base/compiler_specific.h"
|
| +#include "base/macros.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "base/strings/string16.h"
|
| +#include "base/timer/timer.h"
|
| +#include "components/arc/common/intent_helper.mojom.h"
|
| +#include "components/renderer_context_menu/render_view_context_menu_observer.h"
|
| +#include "ui/base/models/simple_menu_model.h"
|
| +#include "url/gurl.h"
|
| +
|
| +class RenderViewContextMenuProxy;
|
| +
|
| +namespace arc {
|
| +
|
| +class ArcBridgeService;
|
| +
|
| +// A class for populating "Open with <ARC app>" menu items in a renderer context
|
| +// menu.
|
| +class OpenWithMenuObserver : public RenderViewContextMenuObserver {
|
| + public:
|
| + using HandlerMap = std::unordered_map<int, UrlHandlerInfoPtr>;
|
| +
|
| + OpenWithMenuObserver(ArcBridgeService* bridge_service,
|
| + RenderViewContextMenuProxy* proxy,
|
| + int main_menu_id_start,
|
| + size_t num_main_menu_items,
|
| + int sub_menu_id_start,
|
| + size_t num_sub_menu_items);
|
| + ~OpenWithMenuObserver() override;
|
| +
|
| + // RenderViewContextMenuObserver implementation.
|
| + void InitMenu(const content::ContextMenuParams& params) override;
|
| + bool IsCommandIdSupported(int command_id) override;
|
| + bool IsCommandIdChecked(int command_id) override;
|
| + bool IsCommandIdEnabled(int command_id) override;
|
| + void ExecuteCommand(int command_id) override;
|
| + void OnMenuCancel() override;
|
| +
|
| + static std::pair<HandlerMap, int> BuildHandlersMapForTesting(
|
| + int menu_id_start,
|
| + size_t num_menu_items,
|
| + int sub_menu_id_start,
|
| + size_t num_sub_menu_items,
|
| + mojo::Array<UrlHandlerInfoPtr> handlers);
|
| +
|
| + private:
|
| + base::string16 GetLabelForCommandId(int command_id) const;
|
| + IntentHelperInstance* GetIntentHelper();
|
| +
|
| + // A callback function called when a mojo IPC issued in InitMenu finishes.
|
| + void OnUrlHandlerList(mojo::Array<UrlHandlerInfoPtr> handlers);
|
| +
|
| + // The callback function for base::RepeatingTimer. This function updates the
|
| + // "loading..." animation in the context-menu item.
|
| + void OnAnimationTimerExpired();
|
| +
|
| + // The bridge service.
|
| + ArcBridgeService* const bridge_service_;
|
| +
|
| + RenderViewContextMenuProxy* proxy_;
|
| + std::set<int> all_command_ids_;
|
| + int main_menu_id_start_;
|
| + size_t num_main_menu_items_;
|
| + int sub_menu_id_start_;
|
| + size_t num_sub_menu_items_;
|
| + GURL link_url_;
|
| + ui::SimpleMenuModel sub_menu_;
|
| +
|
| + // The string used for animation until we receive a response from the ARC
|
| + // process. The current animation just adds periods at the end of this string:
|
| + // 'Loading' -> 'Loading.' -> 'Loading..' -> 'Loading...' (-> 'Loading')
|
| + base::string16 loading_message_;
|
| + size_t loading_frame_;
|
| +
|
| + // A timer used for loading animation.
|
| + base::RepeatingTimer animation_timer_;
|
| +
|
| + // A map from a command ID to a handler.
|
| + HandlerMap handlers_;
|
| +
|
| + // Always keep this the last member of this class to make sure it's the
|
| + // first thing to be destructed.
|
| + base::WeakPtrFactory<OpenWithMenuObserver> weak_ptr_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(OpenWithMenuObserver);
|
| +};
|
| +
|
| +} // namespace arc
|
| +
|
| +#endif // COMPONENTS_ARC_INTENT_HELPER_OPEN_WITH_MENU_CONTROLLER_DELEGATE_H_
|
|
|