summaryrefslogtreecommitdiffstats
path: root/ceee/ie/broker/common_api_module.h
blob: c4b69619574b4ef657ae4d0284d399c148d71c08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2010 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.
//
// Common functions for various API implementation modules.

#ifndef CEEE_IE_BROKER_COMMON_API_MODULE_H_
#define CEEE_IE_BROKER_COMMON_API_MODULE_H_

#include <string>

#include "ceee/ie/broker/api_dispatcher.h"

#include "toolband.h"  // NOLINT

namespace common_api {

class CommonApiResult : public ApiDispatcher::InvocationResult {
 public:
  explicit CommonApiResult(int request_id)
      : ApiDispatcher::InvocationResult(request_id) {
  }

  // Returns true if the given window is an IE "server" window, i.e. a tab.
  static bool IsTabWindowClass(HWND window);

  // Returns true if the given window is a top-level IE window.
  static bool IsIeFrameClass(HWND window);

  // Returns the IE frame window at the top of the Z-order. This will generally
  // be the last window used or the new window just created.
  // @return The HWND of the top IE window.
  static HWND TopIeWindow();

  // Build the result_ value from the provided window info. It will set the
  // value if it is currently NULL, otherwise it assumes it is a ListValue and
  // adds a new Value to it.
  // @param window The window handle
  // @param window_info The info about the window to create a new value for.
  // @param populate_tabs To specify if we want to populate the tabs info.
  virtual void SetResultFromWindowInfo(HWND window,
                                       const CeeeWindowInfo& window_info,
                                       bool populate_tabs);

  // Creates a list value of all tabs in the given list.
  // @param tab_list A list of HWND and index of the tabs for which we want to
  //        create a value JSON encoded as a list of (id, index) pairs.
  // @Return A ListValue containing the individual Values for each tab info.
  virtual Value* CreateTabList(BSTR tab_list);

  // Creates a value for the given window, populating tabs if requested.
  // Sets value_ with the appropriate value content, or resets it in case of
  // errors. Also calls PostError() if there is an error and returns false.
  // The @p window parameter contrasts with CreateTabValue because we most
  // often use this function with HWND gotten without Ids (ie. from
  // TopIeWindow()). This was not the case with CreateTabValue.
  // @param window The identifier of the window for which to create the value.
  // @param populate_tabs To specify if we want to populate the tabs info.
  virtual bool CreateWindowValue(HWND window, bool populate_tabs);
};

// Helper class to handle the data cleanup.
class WindowInfo : public CeeeWindowInfo {
 public:
  WindowInfo();
  ~WindowInfo();
};

}  // namespace common_api

#endif  // CEEE_IE_BROKER_COMMON_API_MODULE_H_