summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/web_intent_picker_cocoa.h
blob: 3363296be9573f80f93fa4d3d647de7801698271 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2012 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 CHROME_BROWSER_UI_COCOA_WEB_INTENT_PICKER_COCOA_H_
#define CHROME_BROWSER_UI_COCOA_WEB_INTENT_PICKER_COCOA_H_
#pragma once

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/intents/web_intent_picker.h"
#include "chrome/browser/ui/intents/web_intent_picker_model.h"
#include "chrome/browser/ui/intents/web_intent_picker_model_observer.h"

class ConstrainedWindow;
class TabContentsWrapper;
@class WebIntentPickerSheetController;
class WebIntentInlineDispositionDelegate;

// A bridge class that enables communication between ObjectiveC and C++.
class WebIntentPickerCocoa : public WebIntentPicker,
                             public WebIntentPickerModelObserver {
 public:
  // |wrapper|, and |delegate| must not be NULL.
  // |browser| should only be NULL for testing purposes.
  WebIntentPickerCocoa(TabContentsWrapper* wrapper,
                       WebIntentPickerDelegate* delegate,
                       WebIntentPickerModel* model);
  virtual ~WebIntentPickerCocoa();

  void OnSheetDidEnd(NSWindow* sheet);

  WebIntentPickerModel* model() { return model_; }

  // WebIntentPickerDelegate forwarding API.
  void OnCancelled();
  void OnServiceChosen(size_t index);
  void OnExtensionInstallRequested(const std::string& extension_id);
  void OnExtensionLinkClicked(const std::string& extension_id);
  void OnSuggestionsLinkClicked();

  // WebIntentPicker implementation.
  virtual void Close() OVERRIDE;
  virtual void SetActionString(const string16& action) OVERRIDE;
  virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
  virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE;
  virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE;

  // WebIntentPickerModelObserver implementation.
  virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE;
  virtual void OnFaviconChanged(WebIntentPickerModel* model,
                                size_t index) OVERRIDE;
  virtual void OnExtensionIconChanged(WebIntentPickerModel* model,
                                      const string16& extension_id) OVERRIDE;
  virtual void OnInlineDisposition(WebIntentPickerModel* model,
                                   const GURL& url) OVERRIDE;

 private:
  ConstrainedWindow* window_;  // Window for constrained sheet. Weak reference.

  // Weak pointer to the |delegate_| to notify about user choice/cancellation.
  WebIntentPickerDelegate* delegate_;

  // The picker model. Weak reference.
  WebIntentPickerModel* model_;

  // Wrapper around the WebContents we're in. Weak Reference.
  TabContentsWrapper* wrapper_;

  WebIntentPickerSheetController* sheet_controller_;  // Weak reference.

  // Tab contents wrapper to hold intent page if inline disposition is used.
  scoped_ptr<TabContentsWrapper> inline_disposition_tab_contents_;

  // Delegate for inline disposition tab contents.
  scoped_ptr<WebIntentInlineDispositionDelegate> inline_disposition_delegate_;

  // Indicate that we invoked a service, instead of just closing/cancelling.
  bool service_invoked;

  // Re-layout the intent picker.
  void PerformLayout();

  // Default constructor, for testing only.
  WebIntentPickerCocoa();

  // For testing access.
  friend class WebIntentSheetControllerBrowserTest;

  DISALLOW_COPY_AND_ASSIGN(WebIntentPickerCocoa);
};

#endif  // CHROME_BROWSER_UI_COCOA_WEB_INTENT_PICKER_COCOA_H_